AlgoViz

Count-Min Sketch updates and estimates

medium 4 min

Increment one hashed counter in each row.

Video lesson · Chapter 1 of 5

Three rows follow the same request stream

0:00 / 3:31

Why the estimate is the smallest counter

1:15Reel

Theory

Read or listen first. About 1 min.

What it is

A Count-Min Sketch hashes a key into one counter in each row. A query addresses those same cells and uses their smallest value as its frequency estimate.

Query one endpoint across three hash rows

Hash 141792Hash 256128Hash 314351One addressed cell per row contributes a value.
Each row’s hash points to one counter for this endpoint. The three selected cells contain 17, 12 and 14.

Why it exists

With nonnegative increments, collisions can add extra traffic to a counter. The smallest addressed counter contains the least contamination among those rows.

Words to know

Collision
Two different keys mapping to the same counter in a sketch row.

How it works

Step through the idea, or press Play.

Step 1 of 3

Update rows. Hash the endpoint once per row and increment each selected counter.

Understand it

Worked example

Count-Min Sketch updates and estimates in practice

A known endpoint has candidate counters 17, 12 and 14. The estimate is 12. If its exact count is 10, at least the cleanest row still contains two increments from other keys.

Related case

Three questions for a tiny memory budget

A telemetry service needs to skip pointless disk reads, estimate traffic for a known endpoint, and count unique devices across regions. Each question allows a different error.

One device crosses regions
A device visits two regionsDevice 9first visitRegion AemptyRegion BemptyCount distinct devices across regions

Estimate the union of observed identities.

Sources