Count-Min Sketch

A d × w grid of counters with d hash functions. Update: add 1 to one cell per row. Query: take the minimum across rows. Estimate is an overcount, never an undercount.

Update O(d) Query O(d) Space O(d·w) Error ≤ eps·N
Slow Fast
d (rows): 3 w (cols): 7 N (total updates): 0 distinct seen: 0
updating cell read cell min (the estimate) collision

What's happening

Type an item and press Add. Each row hashes the item to one column and increments that cell. Query reads the d cells and takes the minimum.

Complexity & Error

OperationCost
Update (add 1 per row)O(d)
Query (min across rows)O(d)
Merge (add two grids)O(d·w)
Space (the grid)O(d·w)
Error (overcount)≤ eps·N
Width wceil(e/eps)
Depth dceil(ln(1/δ))
Guaranteef ≤ est, never below

Operation Log