Computer Science EngineeringVery hard
What is the Theta bound for: for(i=0;i<n;i++) for(j=0;j<n;j++) for(k=0;k<j;k++) c++;
- A. Theta(n^2)
- B. Theta(n^2 log n)
- C. Theta(n^3)
- D. Theta(n^4)
Correct answer: C. Theta(n^3)
For each i the inner two loops execute sum of j = n(n-1)/2 times, so the total is about n^3/2.
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
- After one complete left-to-right bubble sort pass over [5, 1, 4, 2, 8], the array is
- The maximum number of swaps performed by selection sort on n elements is
- Appending n elements one at a time to a dynamic array that doubles its capacity when full costs, per append, an amortized
- With open addressing and uniform hashing, the expected number of probes in an unsuccessful search is at most 1/(1-alpha). What is this…
- A connected undirected graph has 9 vertices and 12 edges. Its cyclomatic number (number of independent cycles) is
- How much extra space does reversing a singly linked list in place (iteratively) require?