TAOCP Vol 3: Sorting and Searching · Week 108
TAOCP 6.1 Sequential Searching
Updated
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.
This week's steps
3 stepsRead §6.1 Sequential Searching
Implement linear search with and without a sentinel and benchmark.
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.
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 15M22▶ Recommended
Arrange a subroutine library on tape when several routines are needed at once.
Exercise 2220▶ Recommended
Find the 1000 nearest records in one scan: which data structure? A heap of the best so far.
Your log
Sign in to log the exercises you work: number, rating, how far you got.
Your notes
Only youSign 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 postsQuestions 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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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.