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

Discussion

What is the time complexity of the Quick Sort algorithm in the average case ?

  • A.O(n)
  • B.O(n log n)
  • C.\(O(n^{2})\)
  • D.O(log n)

Answer: B

Quick sort's average case is O(n log n).

Each partition step does linear work. With reasonably balanced splits the recursion is about log n levels deep, giving n log n in total, and averaged over random inputs or random pivots the expected number of comparisons is about 1.39 n log2 n.

\(O(n^{2})\) is quick sort's worst case, when the pivot is always the smallest or largest element, for example on sorted input with a first-element pivot. O(n) is too fast for any comparison sort, and O(log n) is the depth of the recursion, not the total work.

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

Post your comment

Please log in or register to post a comment.