Registry Synced

HyperLogLog

96 words
1 min read

Reading compass

Now · The Distinct Counting Problem

HyperLogLog

The Distinct Counting Problem

Given a stream of elements, count the number of distinct elements using minimal memory. Trivial solution: Keep a hash set — O(n)O(n) memory. HyperLogLog: O(log⁡log⁡n)O(\log \log n) memory, 1−2%1-2\% accuracy.

Algorithm

  1. Hash each element to a uniform binary string
  2. Find the position rr of the leftmost 1-bit
  3. Track the maximum rr across all elements: RR
  4. Estimate: n≈αmm⋅2Rˉn \approx \alpha_m m \cdot 2^{\bar{R}} Where mm is the number of registers (typically 214=163842^{14} = 16384), αm\alpha_m is a bias correction constant. Join Discord PreviousStreaming AlgorithmsNextRandomized Optimization
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.