The complexity of comparison based sorting algorithms is:
View worked solution
Answer: A
The optimal worst-case time complexity of any comparison-based sorting algorithm is . This limit is established using the decision tree model:
- To sort distinct elements, there are possible permutations (outcomes).
- A binary decision tree representing the comparison-based sorting must have at least leaf nodes to distinguish all possible sorted orders.
- The height of a binary tree with leaves is at least . Therefore, the height (representing the minimum number of comparisons in the worst case) satisfies:
- Using Stirling's approximation, we have:
Since algorithms like Merge Sort and Heap Sort achieve a worst-case time complexity of , this bound is tight. Thus, the complexity of optimal comparison-based sorting is .
Free practice · Your answers on this page are not saved.
