Quiz 2

HyperLogLog

96 words
1 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# 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)$ memory.

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(loglogn)O(\log \log n) memory, 12%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αmm2Rˉ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
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.