UGC NET Paper 2 (Computer Science)Hard

In quicksort, if the recursive call is always made on the smaller of the two partitions first, the worst-case auxiliary stack depth is:

  1. A. O(log n)
  2. B. O(n)
  3. C. O(n log n)
  4. D. O(1)

Correct answer: A. O(log n)

Each pending recursive call on the stack is for a sub-array at most half the size of its parent, so the stack depth is bounded by log2 n even though the total running time can still be Theta(n^2).

More UGC NET Computer Science and Applications questions

Exams that ask this topic