Imagine a firehose of events rushing past: every URL clicked, every search typed, every packet on the network. You want one simple thing — how many times did each item appear? The honest answer is a giant table with one counter per distinct item, and at web scale that table simply does not fit in memory.
The Count-Min sketch, introduced by Graham Cormode and S. Muthukrishnan in 2005, gives up exactness to win on size. Instead of one counter per item, it keeps a small fixed grid of counters — a few kilobytes — and a handful of hash functions. Every item is hashed into one cell per row, and that cell is bumped by one.
To ask how often an item appeared, you look at the same cells and take the smallest of them. The magic property: the answer is never an underestimate. It may be a little too high when unrelated items collide into the same cells, but it can never be too low — a one-sided guarantee that turns out to be exactly what real systems need.
Comments
Loading comments...