# TAOCP 5.4.5 The Oscillating Sort

> Study guide to TAOCP 5.4.5 The Oscillating Sort. A tape sorting scheme that interleaves run creation and merging so the sort oscillates between phases…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 5.4.5 The Oscillating Sort: A tape sorting scheme that interleaves run creation and merging so the sort oscillates between phases, reducing tape movement. Budget about 3 hours; do exercises 4, 1 and 5.

## Key facts {#key-facts}

- Week 104 of 145 on the cracked.guide path, in [TAOCP Vol 3: Sorting and Searching](https://cracked.guide/taocp/volume-3).
- Time budget: about 3 hours.
- 5 exercises in the section, rated 21 to 29; the guide picks 4.
- Picked exercises with Knuth's triangle for recommended: 3.
- Before you start: 5.4.4 Reading Tape Backwards.

## Week 104 goals {#objectives}

By the end of week 104 you can:

- Explain why reading a tape backward reverses each run's order.
- Recognize how backward reading removes rewind time between phases.
- Explain how the oscillating sort interleaves run creation and merging.

## This week's steps {#steps}

- Read §5.4.5 The Oscillating Sort: Skim.
- Work the exercises (4 picked): Start with Ex 4, Ex 1, Ex 5; log what you solve below.
- 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.

## Exercises {#exercises}

This section has 5 exercises, rated 21 to 29, and Knuth marks 1 of them with the triangle for recommended. Only five exercises, so do all of them. 3 is the meaty one: chart Algorithm B on a small case and find where it wastes work.

Worth your time:

- 4 (rated 21): Show one of two table updates in Algorithm B is never read.
- 1 (rated 22): Specify Sobel's original oscillating sort precisely for any number of tapes.
- 5 (rated M25): Which run counts let Algorithm B avoid rewinding? The math one.
- 3 (rated 29, recommended): Chart Algorithm B on three tapes and nine runs, spot the inefficiency and fix it.

## Why it matters {#why}

Honest note: the tape-merging sections describe hardware nobody uses anymore. Knuth himself says much of 5.4 is historical. The ideas (run generation, merge patterns, minimizing passes over slow storage) still apply to external sorting on disks and SSDs, database sort operators and big-data shuffles, so read for those ideas and skim the tape mechanics.

## Before you start {#before}

- 5.4.4 Reading Tape Backwards

## How to approach it {#approach}

Skim.

## Links {#links}

- [Knuth's TAOCP page (editions, errata, MIX/MMIX)](https://www-cs-faculty.stanford.edu/~knuth/taocp.html)
- [Vol 3 errata (plain text, from Knuth)](https://www-cs-faculty.stanford.edu/~knuth/err3.textxt)

---

Source: https://cracked.guide/guide/knuth-w087-1
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
