Lower Bound Comparison Sorting

Intermediate Algorithms and Data Structures English
Also available: Deutsch
Created by Best · 16.08.2026 at 09:13 UTC

Every comparison-based sorter requires at least logarithmically many comparisons relative to n! in the worst case: the decision tree has n! leaves, so its height is bounded below by log2(n!).

Counting/Radix Sort bypass this by using more than comparisons (in restricted key universes).

n n!
3 6
4 24
5 120
## Where used

Justify why pure comparison sorting cannot fall below the information-theoretical limit in the worst case. This opens the door to Counting/Radix if the key universe allows it.

Depth

A comparison sort can be modeled as a decision tree. Each comparison has possible outcomes and splits the remaining possible input orders. For n distinct keys, the tree must distinguish at least n factorial different orders.

A binary tree with height h has at most 2^h leaves. It follows that the height grows at least logarithmically in n! which corresponds asymptotically to n log n. The statement concerns general sorters that derive information solely from comparisons.

Difficulty levels

  1. Interpret comparisons as branches of a decision tree.
  2. Connect the number of leaves to the number of possible permutations.
  3. Explain why Counting Sort does not fall under the same condition.

Pitfalls

The bound says nothing about whether every specific input requires the same number of comparisons. It applies to the worst case of the model and can be circumvented by additional structure of the keys.

University approvals: 0
Tasks
Question 1

Lower bound for comparison-based sorting:

Question 2

Why does the decision tree argument not apply directly to Counting Sort?

Question 3

Implement unsortedness as the number of inversions in the array.

Hint

Nested for loops may use the indices i and j. The return value and hence the counter are of type int.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Algorithms and Data Structures
  • Difficulty: Intermediate
  • Completed: 0 users
Creator
Best
Best
BestBuddy