English

Nearly Optimal Distinct Elements and Heavy Hitters on Sliding Windows

Data Structures and Algorithms 2023-04-12 v3

Abstract

We study the distinct elements and p\ell_p-heavy hitters problems in the sliding window model, where only the most recent nn elements in the data stream form the underlying set. We first introduce the composable histogram, a simple twist on the exponential (Datar et al., SODA 2002) and smooth histograms (Braverman and Ostrovsky, FOCS 2007) that may be of independent interest. We then show that the composable histogram along with a careful combination of existing techniques to track either the identity or frequency of a few specific items suffices to obtain algorithms for both distinct elements and p\ell_p-heavy hitters that are nearly optimal in both nn and ϵ\epsilon. Applying our new composable histogram framework, we provide an algorithm that outputs a (1+ϵ)(1+\epsilon)-approximation to the number of distinct elements in the sliding window model and uses O(1ϵ2lognlog1ϵloglogn+1ϵlog2n)\mathcal{O}\left(\frac{1}{\epsilon^2}\log n\log\frac{1}{\epsilon}\log\log n+\frac{1}{\epsilon}\log^2 n\right) bits of space. For p\ell_p-heavy hitters, we provide an algorithm using space O(1ϵplog3n(loglogn+log1ϵ))\mathcal{O}\left(\frac{1}{\epsilon^p}\log^3 n\left(\log\log n+\log\frac{1}{\epsilon}\right)\right) for 0<p20<p\le 2, improving upon the best-known algorithm for 2\ell_2-heavy hitters (Braverman et al., COCOON 2014), which has space complexity O(1ϵ4log3n)\mathcal{O}\left(\frac{1}{\epsilon^4}\log^3 n\right). We also show lower bounds of Ω(1ϵlog2n+1ϵ2logn)\Omega\left(\frac{1}{\epsilon}\log^2 n+\frac{1}{\epsilon^2}\log n\right) for distinct elements and Ω(1ϵplog2n)\Omega\left(\frac{1}{\epsilon^p}\log^2 n\right) for p\ell_p-heavy hitters.

Keywords

Cite

@article{arxiv.1805.00212,
  title  = {Nearly Optimal Distinct Elements and Heavy Hitters on Sliding Windows},
  author = {Vladimir Braverman and Elena Grigorescu and Harry Lang and David P. Woodruff and Samson Zhou},
  journal= {arXiv preprint arXiv:1805.00212},
  year   = {2023}
}
R2 v1 2026-06-23T01:41:07.568Z