TAOCP Vol 3: Sorting and Searching · Week 92

TAOCP 5.1.3 Runs

Updated

About 6 hours29 exercises, rated 05 to HM42

Summary

TAOCP 5.1.3 Runs: Ascending runs in a permutation, the Eulerian numbers that count permutations by number of runs, and the distribution of run lengths in random data. Budget about 6 hours; do exercises 13, 6 and 2.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §5.1.3 Runs

    Generate random permutations and histogram the run lengths, then compare with the formulas.

  2. Work the exercises (8 picked)

    Start with Ex 13, Ex 6, Ex 2; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 29 exercises, rated 05 to HM42, and Knuth marks 7 of them with the triangle for recommended. Most of the set is M-rated work with Eulerian numbers. Do 13 as a warm-up, then the recommended M21s (6, 15, 20, 27), which are short once the identities from the text are on your desk. 7, 11 and 23 are research-level and 28 is heavy asymptotics; skip them.

Worth your time

  • Exercise 2M22▶ Recommended

    Prove a generalization of the identity that expresses powers through Eulerian numbers.

    Discuss

  • Exercise 6M21▶ Recommended

    Find the flaw in a bogus derivation that n! equals zero. Good practice spotting an illegal swap of sums.

    Discuss

  • Exercise 1305

    Average number of piles in a card-game version of runs. A quick check that you can use the main formula.

    Discuss

  • Exercise 15M21▶ Recommended

    Alternating up-and-down runs, the older notion of a run. Set up the counting and compare with ordinary runs.

    Discuss

  • Exercise 19M26▶ Recommended

    Count rook placements on a chessboard by how many fall below the diagonal. Eulerian numbers show up unexpectedly.

    Discuss

  • Exercise 20M21▶ Recommended

    Connect runs to the number of left-to-right passes needed to read a permutation in order.

    Discuss

  • Exercise 27M21▶ Recommended

    Show that Eulerian numbers also count increasing forests by their leaves. A clean bijection.

    Discuss

  • Exercise 29M30▶ Recommended

    Count permutations by peaks and relate them to alternating runs. The stretch.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 2M22No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 6M21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1305No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 15M21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 19M26No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 20M21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 27M21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 29M30No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

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.

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

Spot a mistake? Report it

Back to week 92