AlgoMaster Logo

Count-Min Sketch

Low Priority18 min readUpdated October 25, 2026
AI Mock Interview

Practice this topic in a realistic system design interview

Premium Video

This video is available to premium subscribers only

Unlock Full Access

Large streaming systems often need to answer a simple question:

How many times did this item appear?

For a small stream, a hash map is enough. For a huge stream with millions of unique items, that hash map becomes too large, because it has to store every distinct key.

A Count-Min Sketch estimates counts using a small, fixed amount of memory.

In this chapter, we'll learn what a Count-Min Sketch is, how it estimates how often items appear in a stream, how to size one, and where systems use it to find the most frequent items without storing a counter for everything.

1. The Problem

Suppose you're building a trending hashtags feature for a social media platform. Every minute, millions of posts come in. Each post contains one or more hashtags. To identify what's trending, you need to track how often each hashtag appears.

The simplest approach is to use a hash map. Each hashtag is a key, and its value is a counter. Whenever a hashtag appears, you increment its counter.

This works well at a small scale. But as the platform grows, so does the number of unique hashtags. Most of them appear only once or twice, perhaps because of typos, jokes, or one-time events. Yet every unique hashtag still needs its own entry in the map. Over time, you could end up storing hundreds of millions of keys, even though most of them are rarely used.

But here's the thing: you don't necessarily need exact counts. You mainly want to identify which hashtags appear much more frequently than others.

So, can we estimate how often something appears using a fixed, small amount of memory, without storing a separate counter for every unique item?

2. What Is a Count-Min Sketch?

Premium Content

This content is for premium members only.