Sorting Lower Bound for Comparison-Based Sorting (cont)
Brief explanation:
Given n elements (no duplicates),
- there are n! possible permutation sequences
- one of these possible sequences is a sorted sequence
- each comparision reduces number of possible sequences to be considered
For a given input,
- the algorithm follows a path from the root to a leaf
- requires one comparison at each level
- there are n! leaves for n elements (e.g. 3! leaves for 3 elements)
- height of such tree is at least log2(n!),
so number of comparisions required is at least log2(n!)
log2(n!) = log2(1) + log2(2) + ... + log2(n/2) + ... + log2(n-1) + log2(n)
log2(n!) >= log2(n/2) + ... + log2(n-1) + log2(n)
log2(n!) >= (n/2)log2(n/2)
log2(n!) = Ω (n log2n)
Therefore, for any comparison-based sorting algorithm, the lower bound is
Ω (n log2 n) .
|