Skip to content
Official PYQ · 2004

GATE CS 2004 Q29 — Searching, Sorting, Hashing

Explain with AI

The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of

Choose one option
View worked solution

Answer: C

The worst-case lower bound for any comparison-based sorting algorithm can be established using the decision tree model.

For an input sequence of nn distinct elements, there are n!n! possible permutations. Any comparison-based sorting algorithm must be able to distinguish between all of these n!n! permutations to correctly sort the input.

In a binary decision tree representing the comparisons:

  • Each internal node represents a comparison between two elements.
  • Each leaf node represents a unique sorted permutation of the input.
  • If the height of the decision tree is hh, the maximum number of leaves it can have is 2h2^h.

To successfully sort all possible inputs, the number of leaves must be at least the number of permutations:

2h≥n!2^h \ge n!

Taking the logarithm (base 2) on both sides:

h≥log⁡2(n!)h \ge \log_2(n!)

Using Stirling's approximation, we know that:

log⁡2(n!)≈nlog⁡2n−nlog⁡2e\log_2(n!) \approx n \log_2 n - n \log_2 elog⁡2(n!)=Θ(nlog⁡n)\log_2(n!) = \Theta(n \log n)

Thus, the minimum height hh (which represents the worst-case number of comparisons) is of the order of Ω(nlog⁡n)\Omega(n \log n). Therefore, the tightest lower bound is of the order of nlog⁡nn \log n.

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

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