English

Multi-dimensional Approximate Counting

Data Structures and Algorithms 2024-11-06 v1

Abstract

The celebrated Morris counter uses log2log2n+O(log2σ1)\log_2\log_2 n + O(\log_2 \sigma^{-1}) bits to count up to nn with a relative error σ\sigma, where if λ^\hat{\lambda} is the estimate of the current count λ\lambda, then Eλ^λ2<σ2λ2\mathbb{E}|\hat{\lambda}-\lambda|^2 <\sigma^2\lambda^2. A natural generalization is \emph{multi-dimensional} approximate counting. Let d1d\geq 1 be the dimension. The count vector xNdx\in \mathbb{N}^d is incremented entry-wisely over a stream of coordinates (w1,,wn)[d]n(w_1,\ldots,w_n)\in [d]^n, where upon receiving wk[d]w_k\in[d], xwkxwk+1x_{w_k}\gets x_{w_k}+1. A \emph{dd-dimensional approximate counter} is required to count dd coordinates simultaneously and return an estimate x^\hat{x} of the count vector xx. Aden-Ali, Han, Nelson, and Yu \cite{aden2022amortized} showed that the trivial solution of using dd Morris counters that track dd coordinates separately is already optimal in space, \emph{if each entry only allows error relative to itself}, i.e., Ex^jxj2<σ2xj2\mathbb{E}|\hat{x}_j-x_j|^2<\sigma^2|x_j|^2 for each j[d]j\in [d]. However, for another natural error metric -- the \emph{Euclidean mean squared error} Ex^x2\mathbb{E} |\hat{x}-x|^2 -- we show that using dd separate Morris counters is sub-optimal. In this work, we present a simple and optimal dd-dimensional counter with Euclidean relative error σ\sigma, i.e., Ex^x2<σ2x2\mathbb{E} |\hat{x}-x|^2 <\sigma^2|x|^2 where x=j=1dxj2|x|=\sqrt{\sum_{j=1}^d x_j^2}, with a matching lower bound. The upper and lower bounds are proved with ideas that are strikingly simple. The upper bound is constructed with a certain variable-length integer encoding and the lower bound is derived from a straightforward volumetric estimation of sphere covering.

Keywords

Cite

@article{arxiv.2411.03071,
  title  = {Multi-dimensional Approximate Counting},
  author = {Dingyu Wang},
  journal= {arXiv preprint arXiv:2411.03071},
  year   = {2024}
}
R2 v1 2026-06-28T19:48:52.915Z