# TAOCP 6.1 Sequential Searching

> Study guide to TAOCP 6.1 Sequential Searching. Searching a list one item at a time, with tricks like sentinels to speed up the loop, and self-organizing…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 6.1 Sequential Searching: Searching a list one item at a time, with tricks like sentinels to speed up the loop, and self-organizing lists that move frequently accessed items toward the front. Budget about 6 hours; do exercises 2, 4 and 5.

## Key facts {#key-facts}

- Week 108 of 145 on the cracked.guide path, in [TAOCP Vol 3: Sorting and Searching](https://cracked.guide/taocp/volume-3).
- Time budget: about 6 hours.
- 22 exercises in the section, rated 15 to M30; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 4, 6, 22 and 15.
- Before you start: chapter 5 basics.

## Week 108 goals {#objectives}

By the end of week 108 you can:

- Implement sequential search with a sentinel and measure the saving.
- Compute expected search cost when keys have known access probabilities.
- Explain how self-organizing lists adapt to skewed access patterns.

## This week's steps {#steps}

- Read §6.1 Sequential Searching: Implement linear search with and without a sentinel and benchmark.
- Work the exercises (8 picked): Start with Ex 2, Ex 4, 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 22 exercises, rated 15 to M30, and Knuth marks 5 of them with the triangle for recommended. Implement sequential search with a sentinel and the move-to-front heuristic, and measure them on skewed access patterns. The scheduling exercises (16 to 21) are a nice detour into ordering by ratio.

Worth your time:

- 2 (rated 15): Restate sequential search for a linked list.
- 4 (rated 17, recommended): Does the sentinel trick work on a linked list?
- 5 (rated 20): When can the unrolled sentinel search be slower than the simple one?
- 6 (rated 20, recommended): Shave the inner loop further with three more MIX instructions.
- 22 (rated 20, recommended): Find the 1000 nearest records in one scan: which data structure? A heap of the best so far.
- 10 (rated M20): The worst ordering of a table, and how it relates to the best.
- 15 (rated M22, recommended): Arrange a subroutine library on tape when several routines are needed at once.
- 11 (rated M30): Limiting behavior of the move-to-front list. The stretch.

## Why it matters {#why}

For small arrays, linear search beats fancier structures. The sentinel trick and move-to-front heuristic are still used in real code.

## Before you start {#before}

- Chapter 5 basics

## How to approach it {#approach}

Implement linear search with and without a sentinel and benchmark. Implement move-to-front on a Zipf-distributed access pattern and measure the average search length.

## Common traps {#traps}

- Forgetting to restore the sentinel slot.

## 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)
- [Wikipedia: Linear search](https://en.wikipedia.org/wiki/Linear_search)
- [Wikipedia: Self-organizing list](https://en.wikipedia.org/wiki/Self-organizing_list)

---

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