TAOCP Vol 3: Sorting and Searching · Week 108

TAOCP 6.1 Sequential Searching

Updated

About 6 hours22 exercises, rated 15 to M30

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.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §6.1 Sequential Searching

    Implement linear search with and without a sentinel and benchmark.

  2. Work the exercises (8 picked)

    Start with Ex 2, Ex 4, Ex 5; 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 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

  • Exercise 215

    Restate sequential search for a linked list.

    Discuss

  • Exercise 417▶ Recommended

    Does the sentinel trick work on a linked list?

    Discuss

  • Exercise 520

    When can the unrolled sentinel search be slower than the simple one?

    Discuss

  • Exercise 620▶ Recommended

    Shave the inner loop further with three more MIX instructions.

    Discuss

  • Exercise 10M20

    The worst ordering of a table, and how it relates to the best.

    Discuss

  • Exercise 11M30

    Limiting behavior of the move-to-front list. The stretch.

    Discuss

  • Exercise 15M22▶ Recommended

    Arrange a subroutine library on tape when several routines are needed at once.

    Discuss

  • Exercise 2220▶ Recommended

    Find the 1000 nearest records in one scan: which data structure? A heap of the best so far.

    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 215No 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 417No 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 520No 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 620No 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 10M20No 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 11M30No 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 15M22No 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 2220No 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

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
  • Chapter 5 basics
How to approach it

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
  • Forgetting to restore the sentinel slot.

Spot a mistake? Report it

Back to week 108