HyperLogLog: How a 12KB Algorithm Can Count 100 Billion Unique Items

Counting billions of unique visitors with a hash set is impractical because memory usage grows linearly, potentially demanding terabytes of RAM. A probabilistic approach called HyperLogLog, rooted in Flajolet and Martin's 1985 paper and refined in a 2007 follow-up, solves this by trading exact accuracy for extreme memory efficiency. The algorithm works by hashing each incoming ID and tracking the longest streak of leading zero bits seen, using that maximum as a statistical estimator of unique item count. A single such counter is highly volatile on its own, but HyperLogLog combines many counters and averages their results to dramatically reduce error. The result is a data structure that can estimate cardinality across hundreds of billions of items while fitting comfortably within a few kilobytes of memory.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in