10-605 · Randomized algorithms

The countmin sketch

A countmin sketch keeps t real vectors r1,…,rt of length m, one per hash function hi. Increment(x,v) adds v to ri[hi(x)] in every row; Retrieve(x) returns the minimum of those t cells. Collisions can only add to a cell, so the estimate is never too small — and it is wrong only if x collides in every row. Step through a stream of cartoon characters below, and click any name to Retrieve it.

 
 
 

Stream of Increment(x, v) calls

The sketch: rows ri, columns 0…m−1

Press Step to process the first Increment.
Hover a cell to see which characters were added into it.

Pseudo-code

Initialize(ε, δ):  m = ⌈e/ε⌉;  t = ⌈ln(1/δ)⌉  r1 = … = rt = 0mIncrement(x, v):  for i = 1, …, t:    ri[hi(x)] = ri[hi(x)] + vRetrieve(x):  return min(r1[h1(x)], …, rt[ht(x)])

True a[x] vs. Retrieve(x)

xa[x]Retrieveerror

Click a row to Retrieve it. Grey rows were never incremented (a[x] = 0); a nonzero Retrieve for them is a Bloom-filter-style false positive.

Parameters & bounds

Cormode–Muthukrishnan: with m = ⌈e/ε⌉ and t = ⌈ln 1/δ⌉, Retrieve(x) ≥ a[x] always, and Retrieve(x) ≤ a[x] + ε‖a‖1 with probability ≥ 1 − δ.