Question

In: Computer Science

The following functions have been calculated as the runtime complexity of various algorithms. Identify the Big-O...

The following functions have been calculated as the runtime complexity of various algorithms. Identify the Big-O complexity, and provide witness values to support your answer. Clearly highlight your answer and show any working out you do.

i. f(n) = 13 + 3n2 – 9n ii.

f(n) = 3n.log2n + 7n

iii. f(n) = nn + 2n5 – 7

iv. f(n) = 2log2n + 4n

v. f(n) = 20 + 2n4 – n2 +n

vi. f(n) = 7n3/4 +3n

Solutions

Expert Solution

Calculating the big-O complexity of a function is easier than calculating it for the algorithm. In case of algorithm you need to take care of so many things like array, loops, nested loops, etc and if you miss any your calculation may go wrong. So,

To calculate the Big-O complexity of a function, these are the points you should keep in mind:

  • Eliminate all the constants
  • Exclude the non-dominants

Lets have a look at the questions:

(i): f(n) = 13 + 3n2  +9n

O(f) = O(13) + O(3n2) + O(9n) ----- GIVEN

O(f) = O(3n2) + O(9n) ----- ELIMINATION OF CONSTANTS

O(f) = O(n2) + O(n) ------ ELIMINATION OF CONSTANTS

O(f) = O(n2) ----- EXCLUSION OF NON-DOMINANT

So, the Big-O complexity of the given function is O(n2)..

(ii): f(n) = 3n.log2n + 7n

O(f) = O(3n log2n) + O(7n) ----- GIVEN

O(f) = O(n log2n) + O(n) -----   ELIMINATION OF CONSTANTS

O(f) = O(n log2n) -----   EXCLUSION OF NON-DOMINANT

So, the Big-O complexity of the given function is O(n log2n)..

(iii): f(n) = nn + 2n5 – 7 (Considering nn as n2)

O(f) = O(n2) + O(2n5) + O(7) ----- GIVEN

O(f) = O(n2) + O(2n5) -----   ELIMINATION OF CONSTANTS

O(f) = O(n2) + O(n5) -----   ELIMINATION OF CONSTANTS

O(f) = O(n5) -----   EXCLUSION OF NON-DOMINANT

So, the Big-O complexity of the given function is O(n5)..

(iv) : f(n) = 2log2n + 4n

O(f) = O(2 log2n) + O(4n) ----- GIVEN

O(f) = O( log2n) + O(n) ----- ELIMINATION OF CONSTANTS

O(f) = O(n) ----- EXCLUSION OF NON-DOMINANT

So, the Big-O complexity of the given function is O(n)..

(v): f(n) = 20 + 2n4 – n2 +n​​​​​​​

O(f) = O(20) + O(2n4) + O(n2) + O(n) ----- GIVEN

O(f) = O(2n4) + O(n2) + O(n) ----- ELIMINATION OF CONSTANTS

O(f) = O(n4) + O(n2) + O(n) ----- ELIMINATION OF CONSTANTS

O(f) = O(n4) ----- EXCLUSION OF NON-DOMINANT

So, the Big-O complexity of the given function is O(n4)..

(vi): f(n) = 7n3/4 +3n​​​​​​​

O(f) = O(7n3/4) + O(3n) ----- GIVEN

O(f) = O(n3/4) + O(n) ----- ELIMINATION OF CONSTANTS

O(f) = O(n) ----- EXCLUSION OF NON-DOMINANT

So, the Big-O complexity of the given function is O(n)..

I hope the answers help..

​​​​​​​Thanks!


Related Solutions

java Introduction: Runtime complexity is an issue when determining which algorithms we should use. Some algorithms...
java Introduction: Runtime complexity is an issue when determining which algorithms we should use. Some algorithms are easy to implement but run too slowly to be useful. Knowing the advantages and disadvantages of different algorithms helps in determining the best solution to a problem. Description: You are to implement two different sorting algorithms and count the number of steps involved with the sort routine (the comparisons and moving positions). Every time a comparison or move is made you should count...
What is the Big O of the following algorithms along with the worst and average cases:...
What is the Big O of the following algorithms along with the worst and average cases: Euclid's Algorithm Brute-Force Matching Topological Sort Lomuto Partition Russian Peasant Algorithm
What is the time complexity of the following code? (in big-O notaion) sum = 0 var...
What is the time complexity of the following code? (in big-O notaion) sum = 0 var = 0 product = 0 for i = 1 to (n+2){ sum = sum + 2i for j = i to [(n*n)+i]{ var = sum + var for k = sum + var{ product = var++ } } } for m + 1 to (j*i){ sum = sum + product }
i need to find complexity and cost and runtime for each line of the following c++...
i need to find complexity and cost and runtime for each line of the following c++ code : // A C++ program for Dijkstra's single source shortest path algorithm. // The program is for adjacency matrix representation of the graph #include <limits.h> #include <stdio.h> // Number of vertices in the graph #define V 9 // A utility function to find the vertex with minimum distance value, from // the set of vertices not yet included in shortest path tree int...
Big-O: Describe the worst case running time of the following pseudocode or functions in Big-Oh notation...
Big-O: Describe the worst case running time of the following pseudocode or functions in Big-Oh notation in terms of the variable n. Show your work a) O( ) int m1(int n, int m) { if (n < 10) return n; else if (n < 100) return happy (n - 2, m); else return happy (n/2, m); } ----------------------------- b) O ( ) void m2 (int n) { j = 0; while (j < n) { for (int i = 0;...
What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n...
What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n log (n2 )        b) T(n)= (nnn)2           c) T(n)= n1/3 + n1/4 + log n      d) T(n)= 23n + 32n      e) T(n)= n! + 2n Write algorithm and program : Find the sum of the integers from 1 through n.     a)Use iterative algorithm and program         b) Use recursive algorithm and program. Order the following functions by growth rate:...
Match the following functions to their respective big-O notation 1. 5 + 0.001n3 + 0.025n 2....
Match the following functions to their respective big-O notation 1. 5 + 0.001n3 + 0.025n 2. 100nlog n + n5 + 100n 3. n2log n + nlog n 4. 2n + n5 + 5n 5. 100n + 0.01n2 A. O(n3) B. O(5n) C. O(n2) D. O(n5) E. O(n2log n)
PYTHON Write the time complexity of the code snippets in Big O notation. Also, add one/two...
PYTHON Write the time complexity of the code snippets in Big O notation. Also, add one/two lines to explain your answer. 1a int a = 0, b = 0; for (int i = 0; i< N; i++) {     a = a + i; } for (int j = 0; j < N; j++) {     b = b + j; } 1b bool isPrime(int N) { if (N == 1) return false; for (x = 2; x <= sqrt(N);...
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 +...
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 + n)(n ^2 + π/2 ) 3. 1 + 2 + 3 + · · · + n − 1 + n
Find the Asymptotic time complexity for each of the functions in the following: #Q2 # to...
Find the Asymptotic time complexity for each of the functions in the following: #Q2 # to denote ayymptotic time complexity use the following notation # O(l) O(m) O(a) O(b) # e.g. traversing through l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is O(l) #1 def merge(): l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] m = [15, 16, 17, 18] lm = [] for l_i in l: lm.append(l_i) for m_i in m:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT