Concept explainers
Counting Operations to Produce Polynomials
In the following section, I will present you with multiple different bodies of code, and it is your job to analyze each code section and build a polynomial that represents the number of abstract operations the code performs. Once we’re done here, we’ll have built a polynomial that we will analyze further (in terms of g(x), c, 5 and k) in the next section. For the following code segments below, count the operations and produce a corresponding polynomial representation.
f(x)=
public static boolean isEmpty() {
return head == null;
}
f(x)
public static int num_occurrences(int n) {
int count = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if( i == j ) continue;
if(strings[i] == strings[j]) {
count++;
}
}
}
return count;
}
f(x)
public static void c(int n) {
for(int a = 0; a < n; a++) {
System.out.println( a * a);
}
num_occurrences(n);
}
f(x)
public static boolean isPrime(int n) {
if(n == 1) return false;
for(int i = 2; i <n; i++) {
if( n % i == 0 ) {
return false;
}
}
return true;
}
Demonstrating | f(x) | < c | g(x) | for all n > k
For each of the polynomials above, pick a reference function (g(x)) and constants c,k such that the g(x) bounds f(x) in the most succinct terms possible for Big O.
1. For the function isEmpty() above, what is ...
f(x)=
g(x)=
c=
k=
2. For the function num_occurences() above, what is...
f(x)
g(x)=
c=
k=
3. For the function c() above, what is...
f(x)=
g(x)=
c=
k=
4. For the function isPrime() above, what is...
f(x)=
g(x)=
c=
k=
Future Exam Practice (optional)
We have more lecture and homework to go before we completely understand this next set of questions, but keep them in mind for future exams.
5. For your Bubble Sort, what is...
f(x)=
g(x)=
c=
k=
6. For your Selection Sort, what is...
f(x)=
g(x)=
c=
k=
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Write a C program for the image attached. Thank youarrow_forwardPython codearrow_forwardDESIGN YOUR OWN SETTING Devise your own setting for storing and searching the data in an array of non-negative integers redundantly. You may just describe the setting without having to give an explicit algorithm to explain the process by which data is stored. You should explain how hardware failures can be detected in your method. Once you have described the setting, make sure to include the following: Write a pseudocode function to describe an algorithm where the stored data can be searched for a value key: if the data is found, its location in the original array should be returned; -1 should be returned if the data is not found; -2 should be returned if there is a data storage error Include a short commentary explaining why your pseudocode works Describe the worst-case and best-case inputs to your search algorithm Derive the worst-case and best-case running times for the search algorithm Derive the Theta notation for the worst-case and best-case running times Maximum word count for…arrow_forward
- All information for this problem is given right here. Google “magic square" and you'll see a magic square is a square (i.e., n x n) matrix of positive integers such that the sum of each row = sum of each column = sum of the top-right to bottom-left diagonal = sum of the bottom-left to top-right diagonal. I want you to start by placing this code in your main.cpp file: // Programmer: .. // Description: Determine if a square matrix is a magic square or not. const int NUM_ROWS_COLS = 3; // Number of rows/columns in the square matrix. // Prototype for function that accepts a two-dimensional matrix of integer // values and returns "true" if the values form a magic square and "false" if not. bool IsMagicsquare (int matrix[NUM_ROWS_COLS][NUM_ROWS_COLS]); #include using namespace std; int main() { int matrix[NUM_ROWS_COLS][NUM_ROWS_COLS] = { 8, 1, 6 }, { 3, 5, 7 }, { 4, 9, 2 } }; if ( IsMagicSquare(matrix) ) { cout « "Matrix is a magic square!" « endl; else cout « "Matrix is NOT a magic…arrow_forwardI need the code from start to end with no errors and the explanation for the code ObjectivesJava refresher (including file I/O)Use recursionDescriptionFor this project, you get to write a maze solver. A maze is a two dimensional array of chars. Walls are represented as '#'s and ' ' are empty squares. The maze entrance is always in the first row, second column (and will always be an empty square). There will be zero or more exits along the outside perimeter. To be considered an exit, it must be reachable from the entrance. The entrance is not an exit.Here are some example mazes:mazeA7 9# # ###### # # ## # # #### # ## ##### ## ########## RequirementsWrite a MazeSolver class in Java. This program needs to prompt the user for a maze filename and then explore the maze. Display how many exits were found and the positions (not indices) of the valid exits. Your program can display the valid exits found in any order. See the examples below for exact output requirements. Also, record…arrow_forwardPython Programmingarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education