Advanced Topic 48 of 52 Data Structures
Count-Min Sketch
Probabilistic frequency estimator using little memory.
How it works
A count-min sketch is a small two-dimensional array of counters indexed by several hash functions. To record an item, increment one counter in each row; to estimate its count, take the minimum across rows. It never underestimates, and the overestimate is bounded by a fraction of the total count with high probability, using memory independent of the number of distinct items.
Step-by-step walkthrough
- An item x arrives in the stream.
- Each row hashes it to one counter.
- The other rows pick their own counters.
- All rows increment those counters.
- To query, take the minimum over the rows, which can only overestimate.
Where it is used
Tracking heavy hitters in network traffic, trending-topic detection, frequency estimation in streaming systems and database query planning use count-min sketches.
Common pitfall
Counts are overestimates because of collisions, which hurts accuracy for rare items. Size the width and depth from the desired error and confidence. It cannot list the items it has seen, so pair it with a heap for top-k. Deletions need non-negative handling.
Where it fits in the course
Count-Min Sketch is topic 48 of 52 in Data Structures, rated Advanced. It follows Cuckoo Hashing. The next topic is HyperLogLog.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Data Structures quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Count-Min Sketch?
Where do people use Count-Min Sketch?
What is the most common mistake with Count-Min Sketch?
What should I learn before this topic?
How can I practice it?
Is Count-Min Sketch hard to learn?
How long does it take to learn Count-Min Sketch?
Which topics are related to Count-Min Sketch?
What should I study after Count-Min Sketch?
Related topics
- Cuckoo Hashing (Data Structures)
- HyperLogLog (Data Structures)
- Van Emde Boas Trees (Data Structures)
- Merkle Trees (Data Structures)