Bloom filters and sketches

O(k)·O(m) bits
1234567891011121%10%1Hash functions kFalse-positive rate (log scale)Predicted, (1 − e^(−kn/m))^k, the fitted bound

Nothing is measured yet. At each of the 12 points, 128 separate filters of 512 bits will each take 60 items, and each will then be asked about 1,500 items it has never seen — 192,000 real queries per point.

Nothing is measured yet. At each of the 12 points, 128 separate filters of 512 bits will each take 60 items, and each will then be asked about 1,500 items it has never seen — 192,000 real queries per point.
  1. 1choose m bits, n items and k hash functions
  2. 2build a filter and insert n real items into it
  3. 3query it with items known not to be in it, and count the false positives
  4. 4put the measured rate beside what the formula predicted
Queries made
0
False positives
0

Complexity

BestO(k)
AverageO(k)
WorstO(k)
Extra spaceO(m) bits
queries at n=60 predicts 1; this run took 0.

The false-positive rate

The chance that a Bloom filter answers "probably present" about something it has never seen is not luck — it follows from three numbers. With m bits, k hash functions and n items inserted, the standard result is (1 − e^(−kn/m))^k, minimised when k is (m/n) ln 2. This page does not assert that. It builds real filters out of real hash functions, inserts real items, asks each filter about thousands of items it has never seen, counts the ones that come back wrongly positive, and draws the measured rate against the predicted curve.

When it is the right choice

Before choosing the size of a filter. The three numbers trade off against each other: more bits buys accuracy with memory, more hash functions buys accuracy with time up to a point and then costs accuracy, and more items spends whatever accuracy is left. The formula turns "how big should this be" from a guess into arithmetic.

How it works

Worth noticing

Cost

Best
O(k)
Average
O(k)
Worst
O(k)
Space
O(m) bits

Worth comparing

All probabilistic structures