Why comparison sorts need n log n time
Question
Someone claims a general comparison-based sorting algorithm can run in time. How do you show this is impossible?
Short answer
A decision-tree counting argument. Each comparison has two outcomes, so comparisons distinguish at most cases, but the algorithm must tell apart all input orderings. Hence in the worst case. Linear time is only possible with extra structure, such as counting or radix sort on bounded integer keys.
Adapted from Joshi, Denson & Downes, Quant Job Interview Questions and Answers, Q5.11, p.158; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solution