Data Structures · Visualization
Count-Min Sketch: Estimate
Count-Min Sketch
Estimation reads the item's d counters and returns the minimum. Time: O(d) reads. Space: O(1) extra.
Big-O: Add/estimate in O(d) hashes; tiny fixed memory.
Count-Min Sketch: Estimate
Count-Min SketchEstimation reads the item's d counters and returns the minimum. Why the min? Every collision adds phantom counts, so each counter is truth-plus-noise and the smallest has the least noise. The answer is never below the truth — one-sided error you can budget for with width and depth.
How Estimate Works
- Hash the item with all d functions to find its cells.
- Read the d counter values.
- Return the minimum — the least-inflated witness.
- Error bound: with width w and depth d, overestimate stays small with high probability.
Estimate Worked Example
Input: Estimate 'apple' and 'fig' (never added)
- 'apple' cells read (3, 2) → min = 2 (truth 2).
- 'fig' hashes to (row0:1, row1:0) → reads (3, 1) → min = 1.
- 'fig' never occurred yet estimates 1 — a collision overestimate.
- Wider grid (more columns) makes such collisions rarer.
Output: apple ≈ 2 ✓ · fig ≈ 1 (phantom — never underestimates)
Press ▶ Run to watch it step by step.
def estimate(sketch, x):
return min(sketch[r][h(r, x)] for r in range(D))
# min = least-inflated witness; never underestimates
# example: estimateBehind the Scenes Execution
Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.
Estimate Time & Space Complexity
When to Use Estimate
- Top-K approximation: estimate then keep a small exact leaderboard
- Database join-size estimation for query planners
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.