Definition · The sketchA Count-Min sketch is a d × w array of counters, all initially zero, with one hash function per row mapping keys to 0..w − 1. To update key x, increment the counter at (i, hᵢ(x)) in every row i. To estimate the count of x, report the minimum of those d counters. The space is d·w counters, fixed in advance, independent of how many distinct keys arrive.
That last clause is why the structure exists. An exact frequency table grows with the number of distinct keys and a stream can have more of them than you have memory for. A sketch has the size you chose when you built it, and the price is an error whose size you can bound.
Theorem · The estimate is never below the truthFor every key x, every stream and every choice of hash functions, the reported estimate is at least the true count of x.
Fix a row i. Every update of x increments the counter at (i, hᵢ(x)), so that counter is at least the true count of x. Every other update increments some counter, possibly this one, and counters are never decremented, so nothing can bring it below that.
The estimate is the minimum over d such counters, each at or above the true count, so it is at or above the true count as well.
□
Theorem · The error boundLet F₁ be the number of updates. For any key x, the estimate exceeds the true count by at least 2F₁/w with probability at most 2⁻ᵈ, provided the rows' hash functions are chosen independently and each spreads keys uniformly.
Fix a row and a key x. For each update of a key other than x, let the indicator be 1 if it lands in x's cell in this row. Each has expectation at most 1/w, so by linearity the expected overcount in this row is at most F₁/w.
The overcount is non-negative, so Markov's inequality applies: P(overcount ≥ 2F₁/w) ≤ (F₁/w)/(2F₁/w) = 1/2.
The rows are independent, and the minimum overcounts by at least 2F₁/w only if every row does, which has probability at most (1/2)ᵈ = 2⁻ᵈ.
□
Markov's inequality is doing all the probabilistic work, and it is the inequality “From an Expectation to a Probability” proves. The textbook statement of this bound is sharper — e/w in place of 2/w, and e⁻ᵈ in place of 2⁻ᵈ — and it needs a concentration result this library does not teach. So the guarantee here is the one that can be proved with what the reader has, and the panel prints 2/w and 2⁻ᵈ for that reason rather than quoting a stronger claim it cannot support.
Example · A heavy hitter in eight countersThe stream is 64 updates over 12 distinct keys: key 1 arrives forty times, keys 2 and 3 arrive three times each, and keys 4 to 12 twice each. With w = 8 and d = 3 the sketch takes 192 increments and 36 reads. Every estimate is at or above the truth; five keys are overcounted, each by exactly 2, and the rest are exact. Key 1's estimate is 42 against a true 40.
The bound allows an error of 2F₁/w = 2·64/8 = 16 with probability up to 1/8, and the worst error observed is 2. That is a factor of eight of slack on this stream, and it is the ordinary situation: Markov is loose, “From an Expectation to a Probability” measured it being loose by factors from 2 to nearly 3849, and nothing about this application changes that.
Notice which keys were overcounted. The heavy hitter was, by 2, and so were four of the light keys — and those light keys were overcounted by the same absolute amount, which is a much larger relative error: an estimate of 4 for a true count of 2 is out by a factor of two, while 42 for 40 is out by five per cent. The bound is additive in F₁ and says nothing about relative error, which is the sketch's real limitation and the reason it is used to find heavy hitters rather than to count rare keys.
What the parameters buy
w controls the size of the error and d controls the probability of exceeding it. Doubling w halves 2F₁/w; adding a row halves 2⁻ᵈ. They are separate knobs and the space is their product, so a sketch with many narrow rows and one with few wide rows can occupy the same memory and offer different guarantees.
The lab's third preset makes the trade visible: w = 12 and d = 4 over a seeded stream of 64 updates across 12 keys. The bound becomes 2F₁/w = 32/3 ≈ 10.67 at a failure probability of 1/16, and every estimate came out exactly right — worst overcount 0. A wider sketch on the same amount of data collides less; the bound improved and the actual error improved more.
And when nothing collides the sketch is exact. The uniform preset — ten keys, six updates each — has a worst overcount of 0 at w = 8 and d = 3, so every estimate equals its truth. That is not the sketch being right about the stream in general; it is this stream's keys happening to miss each other in at least one row each, and a different hash choice would give a different table.
Three numbers, one last time
The exact quantities here are 2F₁/w and 2⁻ᵈ, which are fractions computed from the parameters. The measurement is the worst overcount on the stream on screen, which is 2 on the opening preset and 0 on the other two. The bound is the pair of exact quantities read as a guarantee, and it covers streams nobody has run. The course ends where it began: those are three kinds of number and the page prints all three.