How a hash map finds things instantly, explained in 46 seconds
A hash map doesn't search. A hash function turns the key into the same number every time, the remainder of that number picks a bucket, and a lookup hashes the key again and jumps straight to that bucket: about one check, where a list may need a million.
| Title | How a hash map finds things instantly |
|---|---|
| Subject | Computer science |
| Length | 46 seconds, narrated |
| Format | Vertical, 1080 by 1920 (shown here smaller) |
The script
The narration line by line, with what is drawn for each.
- A list may need a million checks; a hash map needs about one.Comparison: a list against a hash map.
- It stores key-value pairs, like a name and that person's phone number.Named term: key-value pairs.
- Inside are buckets: bucket 0, bucket 1, through bucket 7.One thing splitting into parts: the hash map into its buckets.
- A hash function turns the key Alice into a number, say 1,234, every time.Path of boxes: the key Alice, through the hash function, to a number.
- 1,234 divided by 8 leaves remainder 2, so Alice's pair goes into bucket 2.The path continues: the pair lands in its bucket.
- To find Alice, the search hashes her name again and jumps straight to bucket 2.The path continues: the search goes straight to the bucket.
- Two keys in one bucket is a collision, so that bucket keeps both in a list.The path continues: two keys share one bucket.
- Too few buckets mean long lists; too many waste memory.Three-zone dial: from too few buckets to too many.
- Ten names or a million, a hash map doesn't search; it computes where to look.Words set large: searching set against computing where to look.
Why this works as a short
The hook is a gap
A million checks against about one. The first line names the payoff before any detail, and the last line comes back to it: ten names or a million, a hash map doesn't search; it computes where to look.
One idea, one example
The idea is that a hash map computes where to look. The script follows a single key, Alice, the whole way: hashed to 1,234, placed in bucket 2, then found by hashing her name again. Four lines share one path of boxes, so the viewer never has to start a new picture.
Numbers said aloud
1,234 divided by 8 leaves remainder 2. The sum is small enough to check in your head, which turns "a hash function" from a phrase into a step you can follow. The script also names the trade-off: too few buckets mean long lists; too many waste memory.
More examples
Why the sky is blueScience, 38 seconds
Progressive overload: why adding a little each week worksFitness, 38 seconds
To plan and script a short like this yourself, read how to make educational videos. All three examples are on the examples page.