CMPSCI 251: Mathematics of Computation

David Mix Barrington

Spring, 2007

Discussion Notes #2

from Wednesday 7 February 2007

The Problem of Sorting

We've just seen that there are n! possible permutations of an n-element set. A sorting algorithm must determine which of these possible orders the input is in. A comparison-based sorting algorithm must decide this on the basis of comparisons between pairs of elements. We can represent a comparison-based sorting algorithm by a decision tree. I'll draw on the board a depth-1 decision tree that decides the order of two elements, and a depth-3 tree that decides the order of three elements. Each internal node of the tree represents a comparison between two of the elements, and each leaf node represents and inferred order of the elements.

A tree of depth d can have at most 2d leaves, and a correct tree sorting n elements must have at least n! leaves. Comparing these two numbers gives us the Sorting Lower Bound Theorem, which says that any comparison-based sorting algorithm takes at least log2(n!) comparisons in the worst case.

Questions are in black, answers in blue.

Last modified 13 March 2007