Lesson 10 of 15
20. Probabilistic Data Structures

Memory card and where the analogy breaks

3 min read+10 XP

The memory card (tear this page out)

#QuestionMemory code
20.1Why approximate?Small and nearly right beats huge and exact, when nearly is enough
20.2Bloom filter?No means no; yes means maybe
20.3Counting Bloom filter?Tallies, not ticks, so you can rub one out
20.4HyperLogLog?The longest lucky streak tells you how many tried
20.5Count-min sketch?Mark every board; trust the smallest tally
20.6Top-K?Count roughly, keep the leaders, and swap out the weakest
20.7Size vs error?Decide the error first; the size follows. And never overfill
20.8In interviews?In the set? Bloom. How many unique? HyperLogLog. How often? Count-min. Who's top? Top-K

The whole chapter in one line: Pick the question (in the set, how many unique, how often, who's top), pick the error you can live with, and the answer fits in kilobytes.

Where the analogy breaks

  • A bouncer can remember a face. These structures remember nothing about individuals: you can't ask a Bloom filter or HyperLogLog to list what's inside.
  • A bouncer's guess can be off in any direction. These errors have a known shape: Bloom filters never say a false "no", count-min sketches never undercount.
  • A bouncer can take a bigger card mid-evening. These structures are sized up front; outgrowing them means rebuilding.

Quick check

Five questions on this chapter. Pick an answer, then check it.

quiz