AlgoViz

Bloom filters for membership

medium 4 min

Insert a key by setting several hash-selected bits.

Video lesson · Chapter 1 of 5

Fit membership into eight bits

0:00 / 3:28

Two inserted keys accidentally match a third

1:02Reel

Theory

Read or listen first. About 1 min.

What it is

A Bloom filter marks several positions for every inserted key. During a lookup, any zero at a required position proves absence for a correctly maintained insertion-only filter.

When two inserted keys look like a third

Bit position012345011011Probe {0, 5} → definitely absent
A set bits 1 and 4. B set 2 and 5. A probe for positions 0 and 5 finds a zero, so its key is definitely absent.

Why it exists

Two inserted keys can jointly light up every position needed by a third. A positive result therefore tells the reader when it should consult the exact store.

Words to know

False positive
A possible-membership response for a key that was never inserted.

How it works

Step through the idea, or press Play.

Step 1 of 3

Insert A. Set positions 1 and 4.

Understand it

Worked example

Bloom filters for membership in practice

Key A sets bits 1 and 4. Key B sets 2 and 5. An absent key hashing to 1 and 5 returns a positive even though neither insertion represented that key.

Related case

Three questions for a tiny memory budget

A telemetry service needs to skip pointless disk reads, estimate traffic for a known endpoint, and count unique devices across regions. Each question allows a different error.

One device crosses regions
A device visits two regionsDevice 9first visitRegion AemptyRegion BemptyCount distinct devices across regions

Estimate the union of observed identities.

Sources