MerryDot

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.

TitleHow a hash map finds things instantly
SubjectComputer science
Length46 seconds, narrated
FormatVertical, 1080 by 1920 (shown here smaller)

Preview from the engine we're building; it started as only its title.

The script

The narration line by line, with what is drawn for each.

  1. A list may need a million checks; a hash map needs about one.Comparison: a list against a hash map.
  2. It stores key-value pairs, like a name and that person's phone number.Named term: key-value pairs.
  3. Inside are buckets: bucket 0, bucket 1, through bucket 7.One thing splitting into parts: the hash map into its buckets.
  4. 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.
  5. 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.
  6. 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.
  7. Two keys in one bucket is a collision, so that bucket keeps both in a list.The path continues: two keys share one bucket.
  8. Too few buckets mean long lists; too many waste memory.Three-zone dial: from too few buckets to too many.
  9. 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

To plan and script a short like this yourself, read how to make educational videos. All three examples are on the examples page.