Count-Sketch #
The Count-Sketch of Charikar, Chen and Farach-Colton [CCFC04] estimates
the frequency f_a = count a s of a queried item a in a stream s. Each of its d = 2 r rows
has w counters, a bucket hash h θ : α → Fin w and a sign hash sgn (g φ a) = ±1, with seed
(θ, φ). On reading an item a, every row adds the sign of a to the counter of a; a point
query a reports the median over the rows of the counter of a times the sign of a
(Cslib.Streaming.countSketch, [Chakrabarti2025, Algorithm 8]).
For each fixed query a, with a two-universal bucket family and an independent pairwise independent
family of signs of mean zero, each row errs by more than t with probability at most 1 / 3 once
3 ‖f_{-a}‖₂² ≤ w t², where ‖f_{-a}‖₂² = ∑_{b ≠ a} f_b²
(Cslib.Probability.CountSketch.dens_abs_sum_ite_mul_sign_gt_le); so the median errs with
probability at most (8 / 9) ^ r (Cslib.Streaming.dens_countSketch_error_gt_le). With
3 ≤ w ε² and (8 / 9) ^ r ≤ δ the randomized Count-Sketch with uniform seeds
(Cslib.Streaming.countSketchRandom) answers every point query within ε ‖f_{-a}‖₂, hence within
ε ‖f‖₂ = ε √F₂, except with probability δ (Cslib.Streaming.solves_countSketchRandom,
Cslib.Streaming.solves_countSketchRandom_freqMoment) [Chakrabarti2025, equation (5.7)]. The query
is fixed before the seeds are drawn: there is no claim about adaptively chosen queries.
Memory. On streams of at most m items each counter lies in [-m, m]. Under the public-coin
convention of Cslib.Streaming.Randomized the seeds are not charged, so every sketch drawn uses at
most b bits when (2 m + 1) ^ (2 r w) ≤ 2 ^ b (Cslib.Streaming.spaceLE_countSketchRandom). Only
the initial memory depends on the seeds (Cslib.Streaming.update_countSketch,
Cslib.Streaming.output_countSketch), and with the seeds stored one b-bit encoding of the states
reachable from all seeds exists when (|ι| |κ|) ^ (2 r) (2 m + 1) ^ (2 r w) ≤ 2 ^ b
(Cslib.Streaming.exists_injOn_iUnion_reachable_countSketch). With w = ⌈3 / ε²⌉,
r = O(log δ⁻¹) and hash families with O(log n)-bit seeds, this is the
O(ε⁻² log δ⁻¹ (log m + log n)) bound of [Chakrabarti2025, Section 5.3.2].
Main definitions #
Cslib.Streaming.countSketch: the Count-Sketch with given seeds.Cslib.Streaming.countSketchRandom: the randomized Count-Sketch with uniform seeds.
Main results #
Cslib.Streaming.run_countSketch: the answer is the median of the row estimates.Cslib.Streaming.dens_countSketch_error_gt_le,Cslib.Streaming.solves_countSketchRandom,Cslib.Streaming.solves_countSketchRandom_freqMoment: the accuracy of the Count-Sketch.Cslib.Streaming.spaceLE_countSketchRandom,Cslib.Streaming.exists_injOn_iUnion_reachable_countSketch: its memory.
References #
The Count-Sketch [CCFC04] with 2 r rows of w counters and seeds
ω: row i with seed (θ, φ) = ω i adds the sign sgn (g φ a) of each item a to its counter
h θ a, and a point query a is answered with the median over the rows of the counter of a times
the sign of a [Chakrabarti2025, Algorithm 8]. The seeds are written in the initial memory and read
back by the update.
The randomized Count-Sketch: the sketch with independent uniform seeds for its rows.
The update of the Count-Sketch reads the seeds from the memory: it does not depend on ω.
Reading the stream s from the memory (ω', C) adds to the counter j of row i the sum of
the signs of the items of s hashed to j.
After the stream s, the counter j of row i holds the sum of the signs of the items of s
hashed to j.
The answer of the Count-Sketch to the query a is the median over the rows of
(∑ b ∈ s with h θ b = h θ a, count b s · sgn (g φ b)) · sgn (g φ a).
The Count-Sketch estimates frequencies [Chakrabarti2025, equations (5.6)–(5.7)]: with a
two-universal bucket family h and an independent pairwise independent family sgn ∘ g of signs
of mean zero, if 3 ‖f_{-a}‖₂² ≤ w t² then the Count-Sketch with 2 r rows misses the frequency
of a by more than t for at most an (8 / 9) ^ r fraction of the seeds.
The error of the randomized Count-Sketch is the fraction of bad seeds.
The Count-Sketch answers point queries [Chakrabarti2025, equation (5.7)]: with a
two-universal bucket family h, an independent pairwise independent family sgn ∘ g of signs of
mean zero, 3 ≤ w ε² and (8 / 9) ^ r ≤ δ, for every fixed query a the randomized Count-Sketch
estimates the frequency of a within ε ‖f_{-a}‖₂ = ε (∑_{b ≠ a} f_b²)^{1/2} with error at most
δ on every stream.
The Count-Sketch answers point queries within ε √F₂ [Chakrabarti2025, Section 5.3.2]:
under the hypotheses of Cslib.Streaming.solves_countSketchRandom, for every fixed query a the
randomized Count-Sketch estimates the frequency of a within ε ‖f‖₂ = ε √F₂ with error at most
δ on every stream.
On streams of at most m items, every counter of the Count-Sketch lies in [-m, m].
The memory of the randomized Count-Sketch [Chakrabarti2025, Section 5.3.2]: every sketch it
draws uses at most b bits of memory on streams of at most m items when
(2 m + 1) ^ (2 r w) ≤ 2 ^ b. Under the public-coin convention of Cslib.Streaming.Randomized
only the 2 r w counters are charged; the seeds are not. For the count with the seeds stored see
Cslib.Streaming.exists_injOn_iUnion_reachable_countSketch.
The memory of the Count-Sketch with its seeds stored [Chakrabarti2025, Section 5.3.2]: on
streams of at most m items, the states reachable from all seeds together have a single injective
encoding by b bits as soon as (|ι| |κ|) ^ (2 r) (2 m + 1) ^ (2 r w) ≤ 2 ^ b. Since only the
initial memory depends on the seeds (Cslib.Streaming.update_countSketch,
Cslib.Streaming.output_countSketch), this is the memory of one algorithm whose initial memory is
random, with the seeds charged.