HyperLogLog (Cardinality Estimation)

A probabilistic algorithm and data structure for estimating the number of distinct elements (cardinality) in a multiset or stream using a very small, fixed amount of memory.

Method

Hash elements; observe the maximum number of leading zeros in hash prefixes across registers (stochastic averaging). Harmonic mean of register values yields the estimate, corrected by bias corrections and empirical refinements. Merges by taking register-wise maxima. Typical error ~1–2% with a few KB.

Applications

Distinct count queries in databases and analytics systems (e.g., “unique visitors”), network monitoring, data profiling, distributed distinct counting, approximate query processing.

Advantages

Extremely memory-efficient; mergeable (excellent for distributed systems); fast updates; well-studied and widely deployed; tunable precision vs. space.

Limitations

Approximate; error is relative and stochastic; not suitable when exact counts are mandatory; hash quality matters; very small cardinalities need special handling.

Alternatives

Exact distinct counting (hash sets), Linear Counting, LogLog, MinCount, sampling-based estimators.

Sources

Educational reference only, not professional advice.

All algorithms