TAOCP Vol 3: Sorting and Searching · Week 75

TAOCP 5.1.3 Runs: reading guide

About the book

Ascending runs in a permutation, the Eulerian numbers that count permutations by number of runs, and the distribution of run lengths in random data.

Time About 6 hours this week

Why it matters

Natural merge sort and Timsort exploit runs in real data. Knowing how long runs are in random input tells you when that pays off.

Before you start

  • 5.1.1 Inversions
  • 1.2.6 Binomial Coefficients

How to approach it

Generate random permutations and histogram the run lengths, then compare with the formulas. Build a small table of Eulerian numbers by recurrence.

Exercises

Do every exercise rated 00 to 20 in your head or on paper; they are quick and they check you actually absorbed the definitions. Then pick two or three rated 20 to 25 (M or not) and grind them out fully. Attempt one M25 to M30 and give yourself a hard 90-minute cap before reading the answer. Always read the answer to every exercise you attempted, even the ones you got, because Knuth's answers often teach a second technique.

Traps

  • Confusing runs up with alternating runs (up-down sequences). They are different statistics.

Links

Back to week 75