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

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 }
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:...
I have a function and I was tild to give the big o notation of it...
I have a function and I was tild to give the big o notation of it Analyze the worst-case run-time complexity of the member function reverse() of the List. Give the complexity in the form of Big-O. Your analysis can be informal; however, it must be clearly understandable template <typename T> void List<T>::reverse() { auto current = head; // starting from head node   while(current != nullptr) // till current node is not last (next after last)   {     std::swap(current->next, current->prev); //...
The following ratios have been calculated for the Solar Tech Company. Analyze the profitability of Solar...
The following ratios have been calculated for the Solar Tech Company. Analyze the profitability of Solar Tech Company.                                                                    2015           2014 Gross profit margin                                    37.0%         42.5% Operating profit margin                             4.7%         21.7% Net profit margin                                       1.3%           17.2% Cash flow margin                                       20.4%         25.9%
As computer systems have evolved, there has been a pattern of increasing complexity and sophistication of...
As computer systems have evolved, there has been a pattern of increasing complexity and sophistication of individual components. Compare and contrast the evolution of the input functions of the computer system and the output functions of the computer system in modern computers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT