Skip to content
Official PYQ · 1990

GATE CS 1990 Q3-v — Searching, Sorting, Hashing

Explain with AI

The complexity of comparison based sorting algorithms is:

Choose one option
View worked solution

Answer: A

The optimal worst-case time complexity of any comparison-based sorting algorithm is Θ(nlog⁡n)\Theta(n \log n). This limit is established using the decision tree model:

  1. To sort nn distinct elements, there are n!n! possible permutations (outcomes).
  2. A binary decision tree representing the comparison-based sorting must have at least n!n! leaf nodes to distinguish all possible sorted orders.
  3. The height of a binary tree with LL leaves is at least ⌈log⁡2L⌉\lceil \log_2 L \rceil. Therefore, the height hh (representing the minimum number of comparisons in the worst case) satisfies:h≥log⁡2(n!)h \ge \log_2(n!)
  4. Using Stirling's approximation, we have:log⁡2(n!)≈nlog⁡2n−nlog⁡2e=Θ(nlog⁡n)\log_2(n!) \approx n \log_2 n - n \log_2 e = \Theta(n \log n)

Since algorithms like Merge Sort and Heap Sort achieve a worst-case time complexity of Θ(nlog⁡n)\Theta(n \log n), this bound is tight. Thus, the complexity of optimal comparison-based sorting is Θ(nlog⁡n)\Theta(n \log n).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions