Thought Toys · Strategy & computation · Exhibit 59

The set that's only sure when it says no

A Bloom filter can remember a whole dictionary in a sliver of memory and answer in an instant. The catch: it can be wrong when it says yes — never when it says no — and the more you pour in, the more often its yes is a false alarm.

The bit array, and the false-alarm rate as it fills predicted measured

Fill the filter
Ask the filter
your turn — keep adding words and watch “no” stay honest while “yes” rots

What you're seeing

The grid is the entire filter: 480 bits, nothing else — no words are stored. To add a word, run it through k hash functions — scramblers that turn a word into a bit position and switch on the k bits they point at. To ask “have I seen this word?”, hash it the same way and look: if any of its k bits is still 0, the word was certainly never added — that “no” is airtight, because adding it would have set that bit. If all k bits are 1, the word is probably in — but those bits might have been switched on by other words entirely. That's a false alarm, and it's the only way this structure can ever lie.

Add a handful of words and almost every “yes” is real. Keep adding, though, and the grid lights up; once most bits are 1, any random word's k bits are likely all already set, so the filter waves through strangers it never saw. Watch the curve climb: the false-alarm rate goes from near-zero to near-certain as the array saturates. Through all of it, test a stored word and the answer is always “probably yes” — never a false “no.” That one-sidedness is the whole point: a Bloom filter is a fast, tiny gatekeeper that lets you skip the slow, exact lookup whenever it says “definitely not,” and it's never wrong about that. More hashing isn't automatically safer, either — nudge k up and each word checks more bits (harder to fool) but also sets more bits (fills faster). There's a sweet spot; past it, more hashes make things worse.

The rule, exactly. With m bits, k hashes and n items added, the chance a given bit is still 0 is (11⁄m)kn ≈ eknm, so the false-positive rate is p (1 eknm)k, which rises from ~0 toward 1 as the load nm grows, and is smallest at k* = (mn) ln 2 — the interior optimum where each item sets about half the array. There are no false negatives, ever. Verified in node (improve/verify/59-bloom-filter.js): building the actual filter and probing 300,000 never-added words, the measured false-positive rate matches the formula across four (m,k,n) settings; every stored word is still found (zero false negatives); and the rate climbs monotonically as the filter fills. Negative control: the best k really is interior — over k=1…24 the minimum sits at (mn)ln2, and both one hash and twenty-four hashes do measurably worse; and the naive linear guess p=knm badly over-predicts once loaded, because the real curve saturates rather than growing without bound.

Also in Strategy & computation: The fit that memorizes instead of learns →

All 23 in Strategy & computation
  1. 10The evolution of trust
  2. 23Sorting algorithms
  3. 24PageRank & the random surfer
  4. 25Huffman coding
  5. 26Dijkstra's shortest path
  6. 27Nash equilibria
  7. 33The learning-rate cliff
  8. 36A* pathfinding
  9. 37Braess's paradox
  10. 44Diffie–Hellman key exchange
  11. 45Preferential attachment
  12. 46Aliasing & the Nyquist limit
  13. 47The secretary problem
  14. 49Freeze too fast, stay stuck
  15. 51Cross one line, and its territory closes
  16. 56Catch one error, miss the next
  17. 57Why more processors stop helping
  18. 58Why a busy line explodes
  19. 59The set that's only sure when it says no — you are here
  20. 60The fit that memorizes instead of learns
  21. 61When the wire breaks, pick one
  22. 67Better at both, and still better off trading
  23. 69Everyone was consistent. The vote wasn't.

← the cabinet · Thought Toys — a cabinet of explorable explanations. Exhibit 59.