How often did you see that?

A Count-Min SketchA probabilistic frequency table: a small grid of counters with one hash function per row. Adding an item bumps one cell per row; the estimate is the smallest of those cells, which can only ever overcount. answers "how many times have I seen this?" across a torrent of keys, in a grid that never grows. It never undercounts — it only overshoots a little, and rarely. Two knobs set the deal: width tightens the overshoot, depth makes the guarantee hold more often. One is dear, the other cheap.

Estimate frequencies to within ±% ofε, the error as a fraction of the total count N. The estimate overshoots the true count by at most ε·N — so a bigger stream means a wider absolute band. a-event stream,
and be right% of the time1−δ, the chance the overshoot stays within the ε·N band. Depth d = ⌈ln(1/δ)⌉ buys it — and grows only logarithmically, so it's cheap..
53.1 KiBsketch size

A 2,719 × 5 grid of 4-byte counters estimates any key's count to within +10,000 (0.1% of 10M events), right 99% of the time — and stays 53.1 KiB however many distinct keys stream through.

2,719widthColumns per row, w = ⌈e/ε⌉. The accuracy dimension: halve ε and the width — and the memory — double.
5depthRows, one independent hash each: d = ⌈ln(1/δ)⌉. The confidence dimension, and the min over rows is what kills the overshoot.
53.1 KiBtotal memory
1 MiB560 B
±10%ε = 0.1%±0.005%

Width is ⌈e/ε⌉, so memory scales with 1/ε: ten times tighter accuracy costs ten times the bytes. Accuracy is the expensive dimension — buy only as much as the answer needs.

ConfidenceMemory (at width 2,719)
90%3 rows
31.9 KiB
99%5 rowsnow
53.1 KiB
99.9%7 rows
74.3 KiB
99.99%10 rows
106 KiB
99.999%12 rows
127 KiB

Depth is ⌈ln(1/δ)⌉ — each extra nine of confidence adds only ~2 rows, a near-flat memory cost. Confidence is the cheap dimension; buy plenty. (Each cell is a 4-byte counter — widen to 8 bytes if a single key can exceed ~4 billion.)

Count-Min Sketch sizing · w = ⌈e/ε⌉, d = ⌈ln(1/δ)⌉