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++;

  1. A. Theta(n^2)
  2. B. Theta(n^2 log n)
  3. C. Theta(n^3)
  4. 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.

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic