Machine-translated by Google. Questions are authored in English.
Top

Discussion

In which of the following cases does the worst-case time complexity of Quick Sort occur ?

  • A.When the pivot element is chosen randomly
  • B.When the array is already sorted
  • C.When the pivot element is the smallest or largest element
  • D.None of the above

Answer: C

Quick sort's worst case occurs when the pivot element is the smallest or largest element.

If the pivot is always the minimum or maximum, each partition separates only one element, so there are n levels of partitioning and the running time becomes \(O(n^2)\).

An already sorted array causes this only when the first or last element is chosen as pivot, so it is a special case of option C rather than the general condition. A randomly chosen pivot makes the worst case very unlikely.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.