LearnViz CompSci
Home / Learn / Data Structures / Count-Min Sketch

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

  1. An item x arrives in the stream.
  2. Each row hashes it to one counter.
  3. The other rows pick their own counters.
  4. All rows increment those counters.
  5. 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

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. 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?
Probabilistic frequency estimator using little memory. It belongs to Data Structures and is an advanced-level topic.
Where do people use Count-Min Sketch?
Tracking heavy hitters in network traffic, trending-topic detection, frequency estimation in streaming systems and database query planning use count-min sketches.
What is the most common mistake with Count-Min Sketch?
Counts are overestimates because of collisions, which hurts accuracy for rare items.
What should I learn before this topic?
Start with Cuckoo Hashing, the topic just before it in Data Structures.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Data Structures quiz.
Is Count-Min Sketch hard to learn?
It is an Advanced topic. Expect to read the explanation more than once and to connect it with earlier topics. Working through a small example by hand helps most.
How long does it take to learn Count-Min Sketch?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Count-Min Sketch?
Cuckoo Hashing, HyperLogLog, Van Emde Boas Trees are closely connected. The full list is in the related topics section of this page.
What should I study after Count-Min Sketch?
Continue with HyperLogLog, the next topic in Data Structures.

Related topics