Bloom filters and sketches

O(d)·O(d·w)
Row h0, column 0: 0Row h0, column 1: 0Row h0, column 2: 0Row h0, column 3: 0Row h0, column 4: 0Row h0, column 5: 0Row h1, column 0: 0Row h1, column 1: 0Row h1, column 2: 0Row h1, column 3: 0Row h1, column 4: 0Row h1, column 5: 0Row h2, column 0: 0Row h2, column 1: 0Row h2, column 2: 0Row h2, column 3: 0Row h2, column 4: 0Row h2, column 5: 0001122334455Hash function 0h0row 0Hash function 1h1row 1Hash function 2h2row 2columnhash

An empty 3 by 6 sketch: one row per hash function, and 6 counters in each. A stream of 21 words is about to go in.

An empty 3 by 6 sketch: one row per hash function, and 6 counters in each. A stream of 21 words is about to go in.
  1. 1for each item in the stream, add one to its own cell in every row
  2. 2to estimate an item, read its cell in each row
  3. 3take the smallest of those as the estimate
  4. 4compare it with the true count, which the sketch itself never stores
Counters incremented
0
Cells read
0

Complexity

BestO(d)
AverageO(d)
WorstO(d)
Extra spaceO(d·w)
cells read at n=1 predicts 1; this run took 0.

Count-Min sketch

A Count-Min sketch is a grid of d rows by w columns of counters, with one hash function per row. Every item in a stream adds one to its own cell in every row. To estimate how often an item appeared, read its cell in each row and take the smallest of them. Because a counter can only ever have been added to, every one of those d cells is an upper bound on the item’s true count — so the minimum is too, and the estimate is never below the truth.

When it is the right choice

When a stream is too large to count exactly and the heavy items are the interesting ones: the most-requested URLs, the busiest source addresses, the most-searched terms. The sketch’s size is fixed in advance and does not grow with the stream, which is the property that makes it usable at all at that scale.

How it works

Worth noticing

Cost

Best
O(d)
Average
O(d)
Worst
O(d)
Space
O(d·w)

Worth comparing

All probabilistic structures