Question

In: Computer Science

Find the computational complexity i.e. O(n) etc. for the following four loops and explain why you...

Find the computational complexity i.e. O(n) etc. for the following four loops and explain why you came to that answer:

  1. for (cnt1 = 0, i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
    cnt1++;
  2. for (cnt2 = 0, i = 1; i <= n; i++)
    for (j = 1; j <= i; j++)
    cnt2++;
  3. for (cnt3 = 0, i = 1; i <= n; i*=2)
    for (j = 1; j <= n; j++)
    cnt3++;
  4. for (cnt4 = 0, i = 1; i <= n; i*=2)
    for (j = 1; j <= i; j++)
    cnt4++

Solutions

Expert Solution

Answer:


Related Solutions

Determine the computational complexity of the following language: 0n1n "Computational complexity theory focuses on classifying computational...
Determine the computational complexity of the following language: 0n1n "Computational complexity theory focuses on classifying computational problems according to their inherent difficulty, (how difficult they are to solve) and relating these classes to each other. A computational problem is a task solved by a computer. Some computational problems are impractical as the known algorithm takes too much time and memory to complete."
how do i find a peak in time complexity of O(log(n)) in a list? input: a...
how do i find a peak in time complexity of O(log(n)) in a list? input: a list of numbers or integers output: a possible local peak in the list for an example: calling function [2,3,8,9,5] would return 3 im thinking about using binary search but it would require a sorted list.
Why do factoring and discrete log have the same computational complexity in cryptography?
Why do factoring and discrete log have the same computational complexity in cryptography?
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN)...
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN) B. Evaluate the following postfix expression. 2 3 4 + * C. In an array representation of heap, what are the parent node of a node a[10]? a[9] a[11] a[5] a[20] There is no easy way to access parent node in such representation. D. In an array representation of heap, what are the children nodes (if any) of a node a[10]? a[11] and a[12]...
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
Explain why the successive ionization energies (i.e., IE1, IE2, IE3, etc.) for a given element always increase.
Explain why the successive ionization energies (i.e., IE1, IE2, IE3, etc.) for a given element always increase.
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 }
Argue with proof that whether following asymptotic notations are transitive, reflexive, or symmetric. O(n); o(n); Ω(n);...
Argue with proof that whether following asymptotic notations are transitive, reflexive, or symmetric. O(n); o(n); Ω(n); ω(n); ϴ(n)
Consider the following binds Ca-O, C-O, K-O, O-O and N-O a Which bonds are polar covalent...
Consider the following binds Ca-O, C-O, K-O, O-O and N-O a Which bonds are polar covalent ? b Wich bonds are nonpolar Covalent c Which bonds are ionic ? d Arrange the covalent bonds in order of decreasing polarity
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