Sub topic 2
Why a Count-Min Sketch Estimate Can Only Be Too High
Assume you know basic Python, hash functions, Big-O notation, and expected value. A count-min sketch handles non-negative stream updates, such as event counts.
Why the estimate can only be too high
A count-min sketch stores a grid with d rows and w columns. Each row has its own hash function. When item x arrives, the sketch increments one counter in every row.
To estimate x, it reads the counter selected by x in each row and returns the minimum:
\[ \hat{f}(x)=\min{r=1}^{d} C[r,hr(x)] \]
A counter can contain contributions from x and from other items that hash to the same column. These are collisions. With non-negative updates, collisions add counts; they cannot subtract from x's count. Therefore, every selected counter is at least the true frequency f(x), and their minimum is also at least f(x).
The (ε, δ) guarantee
Let N be the total number of items added to the sketch. With suitable hash functions and dimensions, the estimate satisfies
\[ f(x)\leq\hat{f}(x)\leq f(x)+\varepsilon N \]
with probability at least 1 - δ, for a fixed queried item x.
The parameter ε controls the additive overcount. Smaller ε gives a tighter estimate. The parameter δ controls the probability that the upper bound fails. Smaller δ gives higher confidence.
Sizing the sketch
Choose the width and depth as
\[ w=\left\lceil\frac{e}{\varepsilon}\right\rceil,\qquad d=\left\lceil\ln\left(\frac{1}{\delta}\right)\right\rceil \]
Width controls collision frequency. Depth supplies independent trials, making it unlikely that every row has a large collision. The memory cost is O(wd), independent of the number of distinct items.
Exercise
For ε = 0.01 and δ = 0.01, what width and depth should you use approximately?
Show answer
Use w = ceil(e / 0.01) = 272 columns and d = ceil(ln(100)) = 5 rows.