Computer Science EngineeringVery hard
For n a power of 2, what is the Theta bound of the loop: x=0; for(i=1;i<=n;i*=2) for(j=0;j<i;j++) x++;
- A. Theta(n)
- B. Theta(n log n)
- C. Theta(log n)
- D. Theta(n^2)
Correct answer: A. Theta(n)
Total increments are 1+2+4+...+n, a geometric series equal to 2n-1.
Practise more Algorithms, Data Structures & Programming (ISRO CS) questionsAlgorithms, Data Structures & Programming (ISRO CS): notes and key points
More Algorithms, Data Structures & Programming (ISRO CS) questions
- How many leaf nodes does a binary heap stored in an array of 15 elements have?
- A table of size 7 uses h(k) = k mod 7 with linear probing. After inserting 15, 22, 8 and 1 in that order, at which index does key 1 reside?
- The Bellman-Ford single-source shortest path algorithm has running time
- What is the Theta bound of: for(i=1;i<=n;i++) for(j=i;j<=n;j+=i) count++;
- The recurrence T(n) = 4T(n/2) + n^2 has solution
- The time complexity of topological sorting of a DAG with V vertices and E edges using DFS is