Computer Science EngineeringVery hard
What is the Theta bound of: for(i=1;i<=n;i++) for(j=i;j<=n;j+=i) count++;
- A. Theta(n)
- B. Theta(n^2)
- C. Theta(log n)
- D. Theta(n log n)
Correct answer: D. Theta(n log n)
The inner loop runs about n/i times, and the sum of n/i over i is n times the harmonic number, i.e. Theta(n log n).
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
- 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
- Which of the following standard sorting algorithms is stable?
- In a max-heap, the largest element is always located at
- A simple undirected graph has 10 vertices and exactly 3 connected components. What is the maximum possible number of edges?
- How many distinct spanning trees does the complete graph K4 have?