Info & Theory
A Bloom filter is a compact probabilistic structure that
answers one question: "is this item in the set?" It uses an
array of m bits and k hash functions,
storing no items at all.
Adding an item
Hash the item with all k functions to get
k positions in [0, m), then set those
bits to 1. Bits are never cleared.
Querying an item
- If any of the k bits is 0 → definitely not in the set.
- If all k bits are 1 → possibly in the set.
Because set bits are never reset, a true member always passes — so there are no false negatives. But collisions can make a non-member look present: a false positive.
The error rate
After inserting n items, the probability a random
non-member yields all-ones is approximately
(1 − e^(−kn/m))^k. The term
e^(−kn/m) estimates the share of bits still 0.
Tuning k and m
The error is minimised at k = (m/n)·ln 2, and a
target rate p needs
m = −n·ln p / (ln 2)² bits — about 9.6 bits per
item for 1%.