Tight Bounds for Heavy-Hitters and Moment Estimation in the Sliding Window Model
Abstract
We consider the heavy-hitters and moment estimation problems in the sliding window model. For moment estimation with , we show that it is possible to give a multiplicative approximation to the moment with probability on any given window of size using bits of space. We complement this result with a lower bound showing that our algorithm gives tight bounds up to factors of and As a consequence of our moment estimation algorithm, we show that the heavy-hitters problem can be solved on an arbitrary window using space which is tight.
Keywords and phrases:
sketching, streaming, heavy hitters, sliding window, moment estimationCategory:
Track A: Algorithms, Complexity and GamesCopyright and License:
![[Uncaptioned image]](x1.png)
2012 ACM Subject Classification:
Theory of computation Sketching and samplingFunding:
Authors William Swartworth and David Woodruff were supported by a Simons Investigator Award and Office of Naval Research award number N000142112647.Editors:
Keren Censor-Hillel, Fabrizio Grandoni, Joël Ouaknine, and Gabriele PuppisSeries and Publisher:

1 Introduction
In some situations, such as monitoring network traffic, data is being received at an enormous rate and it is not always worthwhile to store the entire dataset. Instead we may only be interested in some statistics of the data, which we can hope to estimate from a data structure that uses much less space. This motivated the development of streaming algorithms, which process a sequence of updates one at a time, while maintaining some small sketch of the underlying data.
In some applications, it makes sense to focus on only the most recent updates. For instance, when tracking IP addresses over a network [20, 13], we might be more interested in tracking the heavy users on a week-to-week basis rather than over longer time periods. Even if we are interested in longer time periods, we may still be interested in obtaining more fine-grained information about how the heavy users change over time.
This type of problem motivated the sliding window model for streaming algorithms which has a considerable line of work [12, 8, 7, 21]. There are several versions of the sliding window model, but for us our main goal is to respond to queries about the previous elements of the stream.
We consider perhaps the two most foundational problems in streaming algorithms: moment estimation and heavy-hitters. Both of these models have received an enormous amount of attention in the streaming literature, beginning with [11] who proposed the CountSketch algorithm for finding heavy items, all the way to [6] who gave the optimal space bound for insertion-only streams 111This means that items may be added to the stream, but not removed., removing one of the factors of CountSketch. While fully tight bounds are known for heavy-hitters (up to a factor in insertion streams), in the sliding window model tight bounds are still unknown. Previous work [7] gave a lower bound, and a upper bound in the sliding window model. We close this gap, and show that a dependence suffices for computing heavy-hitters on a particular sliding window.
In the moment estimation problem, the goal is to approximation the moment for the frequency vector of all items inserted into the stream. Like heavy-hitters, this problem has a long history going back to [1]. Since then, a line of work has led to nearly tight bounds both for large moments , which does not admit polylogarithmic sized sketches [2, 15], as well as the small moments [14, 18] that we consider here. While this problem has received considerable attention in the sliding window model [8, 10, 21], there still remains a gap in the literature. We aim to close this gap for the problem of estimating the moment on a sliding window.
1.1 Our models
The sliding window model
There are several slightly different models that one can consider. By default we consider an insertion-only stream of length consisting of items In the sliding window model, there is a window of size consisting of the most recent updates to the stream. A correct sliding window algorithm may be queried for the desired statistic at any time and it must produce a correct estimate for the statistic on the stream of the most recent updates. When we refer to the failure probability for such an algorithm, we mean the probability of failure for a single query (for an arbitrary value of ).
One could also consider the problem of tracking a stream statistic over the sliding window at all times. This could be accomplished in our framework simply by making the failure probability .
One could also consider a more general model where there is no fixed window. Instead at a given query time , the algorithm receives a positive integer and must estimate the stream statistic on the portion of the stream in The difference is that is now not known until runtime. Our algorithms all apply to this more general model, and our lower bounds hold in the standard sliding window model. This model may be useful if one wants to observe how the stream has changed up to the present time. For instance if we were monitoring network traffic, we might be interested in which IP addresses occurred frequently in the past hour, day, week, etc.
moment estimation
In the version of the moment estimation problem that we consider, we receive a series of insertion-only updates At any point in time the algorithm may be asked to output an estimate of the moment of the window consisting of updates If is the frequency count of universe item over the window, then the moment over the window is defined to be In order to be correct, the algorithm must satisfy with probability at least
Heavy hitters
We say that item is -heavy for a frequency vector if In the -heavy hitters problem the goal is to output a collection of universe items such that all -heavy items for are contained in and such that all elements of are at least -heavy where is a constant.
1.2 Prior Work
[8] introduced the smooth histogram approach for solving problems in the sliding window model. For a function , given adjacent substreams , and , an -smooth function demands that if , then for some parameters . Throughout the stream, they use the smooth histogram to remove the unnecessary information and only keep track of the time when differs by . For , their work achieves space .
[21] introduced a new tool called a Difference Estimator. The idea is to estimate the difference of and with additive error , given that , the dimension of the sketch only needs to be . They use the idea in [8] to maintain a constant factor partition on the top level. Then using a binary tree-like structure to give a fine-grained partition, they use a Difference Estimator to exclude the part that is not in the window.
[6] gives a bits of space algorithm to give strong tracking over in insertion-only stream. Also, [4] generalize this to . They introduce a weak tracking property, which is a key motivation for our Strong Estimator .
For heavy hitters, [7] gives a algorithm, with the estimation being the bottleneck. If given the estimation over the window, then their algorithm can work in space . This is the result we apply to obtain improved heavy-hitter bounds from our estimator. They also prove an lower bound for the heavy hitter problem in the sliding window model.
1.3 Our Results
Problem (in Sliding Window Model) | Previous Bound | New Bound | ||
-Heavy Hitters, |
|
|||
Estimation, | [21] |
|
estimation
We give an algorithm for moment estimation for that achieves optimal bounds in the sliding window model, in terms of the accuracy and the window size .
Theorem 1.
There is an algorithm that uses
bits of space, and solves the moment estimation problem in the sliding window model.
Note that this result is for approximating the on any fixed window with probability. To track at all times, and guarantee correctness at all times with good probability, one could apply our algorithm times in parallel, and take the median estimate at each time.
Heavy hitters
As a consequence of our approximation scheme, we obtain an optimal heavy-hitters algorithm by combining with the results of [7].
Theorem 2.
Given and , there exists an algorithm in the sliding window model that, with probability at least , outputs all indices for which frequency , and reports no indices for which . The algorithm has space complexity .
An earlier version of [7] claimed this bound for the stronger problem of tracking the heavy-hitters on the window at all times. Unfortunately this original bound was incorrect, and their algorithm actually gives a dependence, even in our setting where we are interested in obtaining good success probability for a single window.
Lower bounds
We also show that our estimation algorithms are tight in the sliding window model up to factors. Specifically, we show
Theorem 3.
Fix . Suppose that is a streaming algorithm that operates on a window of size , and outputs a approximation of on any fixed window with probability. For must use at least
space.
The first term in the lower bound is our contribution. The second term applies to general insertion-only streams, and follows from a recent work of [5]. While the lower bound only applies to , our proof also applies to if the stream is allowed to contain empty insertions that do not affect the frequency counts, but that move the window. (Without empty insertions is trivial, since is always the window size.)
1.4 Notation
We use to denote the length of the stream, be the universe size, and to denote the elements in the stream. For sliding window, we use to denote the window size. We use to denote a constant degree polynomial in . We assume .
For interval , we use to denote the frequency vector of elements . For , we use to denote the norm of the frequency vector , more specifically, , and to denote the moment of frequency vector , more specifically, . For window , we also use or to denote the norm or frequency moment on window . We use to denote .
1.5 Technical Overview
estimation
To motivate our approach, consider approximating to within a constant factor. We first recall the framework introduced by [9] for the sliding window model. The rough idea is to start a new estimation sketch at each point in the stream. This clearly gives a sliding window estimate, but uses far too much space. However, the observation is that if sketch and sketch give similar estimates for at a given point in the stream, then they will continue to do so for the remainder of the stream. The estimate given by sketch is sandwiched between the estimates from the neighboring sketches, so sketch is redundant, and we may safely delete it. After deleting all redundant sketches, we are left with sketches (for constant ) with geometrically increasing estimates.
Each of these sketches uses bits of space to estimate with probability , so this approach requires bits. Since we only store sketches at a time, it might seem that we can take This is a subtle point and has been a source of error in prior work.
In fact we cannot take if we are only guaranteed that our sketches correctly estimate with probability at least . To see why, suppose that each sketch we create is correct with probability at least and is otherwise allowed to be adversarially incorrect with probability With it is likely that two consecutive sketches will eventually both be incorrect. In that case, they can conspire to in turn sandwich and wipe out all sketches in front of them, from which we will not be able to recover. While extreme, this example illustrates that an estimation sketch with a failure probability guarantee is not sufficient for us. This is why prior approaches for estimating the norm or moment in sliding windows require bits of space, with one of the logarithmic factors arising from the need for sketches with high success rates. These high-success-rate sketches necessitate union bounds over all sketches, even though most of them are not kept by the algorithm when we make a query.
Of course we should not expect sketches to fail this way in practice. Could there be a somewhat stronger guarantee that rules out this type of adversarial behavior? In this work, we overcome this limitation by introducing a new tool: the Strong Estimator . This estimator enables a refined analysis that avoids the union-bound overhead, allowing us to achieve the first space complexity which breaks the bit barrier.
The intuition of Strong Estimator is for a window , we do not need our estimator to be right (meaning give an approximation) on any sub-interval of this window, but rather only an additive error: fraction of the norm of the window suffices for maintaining the timestamps. Thus we can avoid the union bound for all sub-intervals to be right. The intuition is similar to the weak tracking in [4].
In Section , we show that Strong Estimator with the simplest algorithm in [8] suffices to give an approximation to the norm of the sliding window. However, this simple algorithm uses bits of space, which requires a high dependence on .
In Section , we introduce Difference Estimator [21] to improve the dependence. We first use our simple algorithm to give a constant factor partition on the top level. We then use a binary tree-like structure to make a more detailed partition between the top level, and use Difference Estimator estimator to exclude the contribution that is not in the window. The algorithm in [21] requires space. The extra factor also comes from the high success probability requirement. Using the Strong Estimator and the structure of their algorithm, we can obtain an algorithm using bits of memory. We further discover that the bottleneck of the algorithm comes from the Difference Estimator , which can be stored by rounded values using the rounding procedure in [16]. We thus improve the space to bits, which gives a separation between and . We further prove a lower bound on moment estimation over sliding windows, see below, showing that our algorithm is nearly optimal.
Heavy Hitters
[7] showed that if one has an estimation algorithm over a sliding window, then one can find the heavy hitters with additional bits of space. In [17], they show that an - heavy hitter algorithm for also finds - heavy hitters for . Thus, using our simplest algorithm to provide a constant estimation over the window will give us an algorithm that uses bits of space, and returns all the - heavy hitters. This matches the lower bound for heavy hitters in [7].
Lower Bounds
For our lower bound for estimation, we construct a stream that consists of roughly blocks, where each block has half the value of the prior block. Within each block, we place items that are each -heavy for the block, and arrange them so that each of these heavy items occurs in a contiguous “mini-block”. Overall, there are of these “mini-blocks”.
The main observation is that a correct streaming algorithm for -moment estimation in the sliding window model must remember the location of each mini-block. Doing so requires bits of space per mini-block as long as there are at least, say, disjoint positions that each block can occur in, resulting in our lower bound.
To see why our algorithm must remember each location, consider one of the heavy items in our construction, and suppose we want to decide whether the mini-block for occurs entirely before or entirely after stream index We first shift the sliding window so that it begins at index . We would like to decide whether or not occurs in the resulting window. By the geometric decay of the blocks, remains heavy for the entire window. Then to decide if remains in the window we append copies of to the window, where is a rough estimate of the over the window. If does not occur in the window, then appending the ’s increases the by On the other hand, if does occur roughly times in the window then the increases by Since is approximately the moment of the window, a heavy-hitters algorithm can distinguish between these two cases. A minor issue is that as stated, we would need to append the ’s without shifting the window past the index . However we can easily fix this by appending the ’s before performing appending singletons to accomplish the shift. To make the above intuition precise we give a reduction from the IndexGreater communication game in Section 5.
2 Preliminary Results
In this section, we will introduce some basic definitions and lemmas that form the foundation of our Strong Estimator. We will also introduce the previous results for heavy hitters. We first require the following definition for -stable distribution.
Definition 4 (-stable distribution. [22]).
For , there exists a probability distribution called the -stable distribution so that for any positive integer with and vector , then for .
The probability density function of a -stable random variable satisfies for , while the normal distribution corresponds to . Moreover, [19] details standard methods for generating -stable random variables by taking uniformly at random from the interval uniformly at random from the interval , and setting
These -stable random variables are crucial to obtaining our Strong Estimator.
Definition 5 (Strong Estimator).
Let , and let be the sequence of stream elements. Let denote the frequency vector for elements We say that has the Strong Estimator property on the window if with probability , we have the bound for all sub-windows simultaneously. We say that has the Strong Estimator property if it has the Strong Estimator property on all windows
For simplicity, we will use to denote the estimate .
To support the construction and analysis of such an estimator, we rely on several probabilistic tools. Lemma 6 gives a Chernoff-type concentration bound for -wise independent random variables. Lemma 7 provides tail bounds on the supremum of inner products between a -stable random vector and a sequence with an increasing frequency vector.
Lemma 6 ([3]).
Let be a sequence of -wise independent random variables, and let . Then
Lemma 7 ([4]).
Let satisfy . Let have -wise independent entries marginally distributed according to . Then for some depending only on ,
Finally, we include two additional lemmas that are essential for our heavy hitter detection algorithm in the sliding window model.
Lemma 8, due to Braverman et al. [7], shows that a constant-factor approximation to the norm within a window suffices to recover all -heavy hitters under the norm, with provable accuracy guarantees and near-optimal space complexity.
Lemma 8 ([7]).
For a fixed window , if given a approximation of , then there is an algorithm that outputs all the heavy hitters for within the window, and can guarantee that all the output elements have frequency . This algorithm uses and has success probability .
To extend this result to the setting for any , we use Lemma 9, which establishes that any algorithm capable of recovering -heavy hitters under (with a suitable tail guarantee) also successfully identifies all -heavy hitters under the norm.
Lemma 9 ([17]).
For any , any algorithm that returns the -heavy hitters for satisfying the tail guarantee also finds the -heavy hitters for .
3 Warmup: Constant-factor approximation
In this section, we will introduce our result for Strong Estimator. This estimator enables us to design a constant-factor approximation algorithm for , and in combination with previous results, it leads to a nearly optimal algorithm for identifying -heavy hitters over sliding windows.
3.1 Constructing a Strong Estimator
First, we will show how to construct a space efficient Strong Estimator defined in Definition 5.
Construction 10.
Let , and be parameters to be specified later, the Strong Estimator takes to be a random matrix with entries drawn according to , and such that the rows are r-wise independent, and all entries within a row are s-wise independent. For frequency vector , the estimate is given by .
The following lemma shows that, by appropriately setting the parameters , , and , the above construction yields a valid Strong Estimator.
Lemma 11.
Let with , , and . Given a stream of elements , Construction 10 yields an Strong Estimator by setting the parameters as follows:
To show the space efficiency, we also analyze the space complexity of storing the matrix used in the construction.
Lemma 12.
The memory required to store the matrix for an Strong Estimator is
Last, we will show an additional property of Strong Estimator, which is crucial for solving estimation over sliding windows.
Lemma 13 (Additional Property for the Strong Estimator).
The Strong Estimator has the following property:
For a sequence of elements in the stream and a window , with probability , for any interval that , .
3.2 Constant-factor approximation
First, we will introduce the algorithm given in [8]: it maintains timestamps to track the times at which changes by a factor of . This algorithm requires bits of space, where one factor accounts for the number of sketches, another arises from the need for high success probability in order to apply a union bound over all sketches, and the final comes from the fact that each entry in the sketch requires bits.
Our key improvement over their algorithm is that, by using the Strong Estimator , we no longer require the sketches to have high success probability. The Strong Estimator provides guarantees over all sub-intervals directly, eliminating the need for a union bound.
We present an -approximation algorithm for over sliding windows that uses space. This is the first algorithm achieving space for this problem. As estimation and estimation are fundamentally the same, we do not distinguish between the two here.
The following theorem formalizes the guarantees of our approach:
Theorem 14.
For any fixed window , with probability , Algorithm 1 will give an approximation of , and use bits of space.
We now apply our algorithm to the heavy hitter problem in sliding windows. Combining our -approximation for with known results for heavy hitters (Lemma 8 and Lemma 9), we obtain the following result:
Theorem 15 (Main Theorem on Heavy Hitters).
Given and , there exists an algorithm in the sliding window model that, with probability at least , outputs all indices for which frequency , and reports no indices for which . The algorithm has space complexity (in bits) .
Proof.
We use Algorithm 1 to obtain a approximation over , the rest of the proof follows by Lemma 8 and Lemma 9.
Input: Stream , window length , approximate ratio and error rate , parameter .
Output: At each time , output a approximation to in window .
Initialization:
-
1.
Generate the matrix for an Strong Estimator, where .
-
2.
Random matrix for a Indyk’s p-stable Sketch, where .
Let be the estimated value of from Strong Estimator on data stream , and be the estimated value of from Indyk’s p-stable Sketch.
During the Stream:
Define to be the -th timestamps when the stream goes to . The following lemma shows that the norm does not decreases significantly between two consecutive timestamps.
Lemma 16.
Let , for fixed window , with probability , either , or .
Now we prove theorem 14.
Proof of Theorem 14.
Our Indyk’s p-stable Sketch will give a approximation with probability . By a union bound over the event of Lemma 16 and the condition that Indyk’s p-stable Sketch is right, by adjusting the constant factor for , we obtain an approximation of with probability .
For the space, as the value is bounded by , the number of timestamps will be bounded by .
For each timestamp, we keep a vector with dimension for the Strong Estimator , and a vector with dimension for Indyk’s p-stable Sketch . So the total space for the sketches is , as we have assumed . The space to store the matrix is of lower order by Lemma 12.
4 Improving the dependence
4.1 Preliminary Results
Here we use to denote for frequency vector .
First, we introduce the definition and construction of Difference Estimator, which is essential in our algorithm that gives tight bound on estimation over sliding window.
Definition 17 (Difference Estimator. Definition 8.2, [21]).
Given a stream and fixed times , , and , let frequency vectors and be induced by the updates of between times and . Given an accuracy parameter and a failure probability , a streaming algorithm is a -suffix difference estimator for a function if, with probability at least , it outputs an additive approximation to for all frequency vectors induced by for times , given for a ratio parameter .
Lemma 18 (Construction of Difference Estimator. Lemma 4.9, Lemma 3.6 [21]).
Let the dimension .
For , it suffices to use a sketching matrix of i.i.d. entries drawn from the -stable distribution , with dimension to obtain a -difference estimator for . To store such a matrix requires space.
Moreover, the estimation of is given by:
-
1.
For a parameter , let each and .
-
2.
Output the arithmetic mean of .
For , it suffices to use a sketching matrix that each entry of is a 4-wise independent random sign scaled by to obtain a -difference estimator for . To store such a matrix requires space.
The estimation of is given by .
Next, we introduce the rounding procedure described in [16]. Although this procedure is originally designed for a distributed setting, the process of merging two sketches can be interpreted as two nodes transmitting their respective sketches to a parent node, which then performs a new rounding operation based on the information received from its children.
Definition 19 ([16] Rounding random variable).
For any real value , let and be such that . Now fix such that:
We then define the rounding random variable by
Procedure 1 (Recursive Randomized Rounding).
-
1.
Choose random vector using shared randomness.
-
2.
Receive rounded sketches from the children of node in the prior layer (if any such children exist).
-
3.
Compute .
-
4.
Compute . If player , then send it to the parent node of in . If , then output as the approximation to .
Lemma 20 (Lemma 2, [16]).
Let be the universe space, and be the total point in the graph, be the diameter of this graph, . Fix , and let . Then the above procedure when run on for a sufficiently large constant , produces an estimate of , held at the center vertex , such that . Moreover, over the randomness used to draw , with probability for , and with probability for Gaussian , we have . Thus, with probability at least , we have
Moreover, if where each is a 4-wise independent Rademacher variable, then the above bound holds with (and with probability ).
Now, we give our own rounding procedure.
Procedure 2.
Suppose we want to update the rounded sketch of window . The sketch has a matrix for . For , the sketch has a matrix , with each entry being a Rademacher variable and each row being 4-wise independent. The precise sketch for window is . Let be the sketch vector after the rounding procedure.
There are 2 cases: First is given a non-rounded sketch, and then rounding the sketch. In this case, for each , .
The second case is given the rounded sketch of 2 sub-intervals and . For this case, .
Lemma 21.
Let be a window, be the sketching matrix (meaning each entry is sampled from if , or is a Rademacher variable if ), and we are running procedure described in Procedure 2 with parameter to get a rounded vector for sketch . Then for all , we have .
4.2 Algorithm Overview
The structure of our algorithm follows [21]. Let the current time be and query window be . Our algorithm first uses Algorithm 1 to maintain a constant factor partition on the top level. We will have timestamps on the top level. Let them be .
For each of the pieces of the stream, we will partition the substream into more detailed timestamps. We will have a binary tree-like structure, with at the top level, and each level will keep roughly timestamps. Define the -th timestamp on level between top level to be .
We will use Difference Estimator to estimate the difference of between 2 nearby timestamps and the current time , to exclude the contribution from to . As the Difference Estimator is maintained by a binary tree-like structure, we only need to query the Difference Estimator a constant number of times on each level. So if each Difference Estimator gives an additive error of , then our final approximation will have an additive error of . So a value suffices and the Difference Estimator uses space in total.
To maintain the binary tree-like structure for the Difference Estimator, the algorithm by [21] uses a -stable sketch with high success probability, and thus by union bound, these sketch always can rule out unnecessary timestamps and retain only the essential ones.
Our algorithm relies on the analysis of Strong Estimator, and no such union bound will be used (thus saving a factor of ), so it will require a more careful analysis. In the following content, we introduce our new techniques.
Input: Stream , window length , approximate ratio and error rate , parameter .
Output:At each time , output a -approximation to for window .
Initialization: for all ,
-
1.
Let , prepare the matrix for Strong Estimator to maintain a constant factor partition on the top level.
-
2.
Prepare the matrix for a Indyk’s p-stable Sketch with dimension .
-
3.
To maintain the subroutine level, for each , prepare random matrices for a large constant , each responsible for an Strong Estimator . Store them in a queue .
-
4.
For each level , generate the matrix for the -Difference Estimator, with dimension .
4.3 Rounding Techniques
In this subsection, we present several space-saving techniques that allow us to maintain correctness guarantees while significantly reducing the storage requirements of the sketching data structures. First, we describe how rounding can be applied to the Strong Estimator sketches to reduce the number of bits required per entry. Next, we address the challenge of bounding the number of timestamps in the absence of a global union bound, introducing a rotating random set technique that probabilistically limits the number of active sketches. Finally, we apply a fine-grained rounding scheme to compress both the Indyk’s p-stable Sketch and Difference Estimator sketches, ensuring that their space usage remains within our overall complexity bounds.
Storing the Sketch via Strong Estimator
We now describe how to apply rounding to the estimates computed by Strong Estimator to achieve space efficiency.
Throughout the algorithm, the sketch is used to estimate the norm over the interval from timestamp to either another timestamp or the current time. While we maintain exact estimates for intervals ending at the current time, we observe that for estimates ending at previous timestamps , we can round the values to save space. Specifically, we round to the nearest power of . The following claim shows that this rounding preserves the Strong Estimator property up to a small additive loss:
Claim 22.
Let be a stream and an arbitrary window. Suppose satisfies the Strong Estimator property on . Define to the nearest power of . Then satisfies the Strong Estimator property on .
Thus, in our analysis, since we use -Strong Estimator , we may safely treat the rounded sketches as -Strong Estimator without loss of generality.
However, directly storing rounded values (where is the number of timestamps) would still be space-inefficient. To address this, we introduce the following compression technique:
Technique 1.
For each timestamp , we maintain an array of length . The -th entry stores the rank of the earliest timestamp such that .
A potential issue with this scheme is that the value might be “overestimated” due to a later timestamp with . However, this does not violate the Strong Estimator property, since .
Therefore, this approximation remains valid, and the total space required to store all the Strong Estimator sketches is reduced to bits.
Challenges in Bounding the Number of Timestamps
The analysis in [21] relies on applying a union bound over all sketches and all times, which introduces an additional factor in the space complexity. In contrast, we leverage the Strong Estimator to eliminate the need for such a union bound. However, this also introduces new challenges.
Consider the current window , and let be the earliest index such that . Conditioned on the Strong Estimator satisfying its guarantee over , we can show that the number of timestamps at the first level is bounded and provides reliable guidance for constructing Difference Estimator .
The complication arises because this guarantee only holds with probability , and without a global union bound, we cannot ensure that the number of timestamps is always bounded across time. For instance, if the same matrix is reused across all Strong Estimator instances, then in the unlikely case that these matrices fail simultaneously, the number of timestamps could grow unbounded.
To mitigate this, we introduce the following technique:
Technique 2 (Rotating Random Sets).
For each level , we maintain a queue that holds independent random matrices , for a sufficiently large constant .
Each Strong Estimator instance uses a distinct matrix from the queue that has not been used before. When a sketch is deleted, its corresponding matrix is returned to , making it available for reuse.
Lemma 23.
Fix any time . With probability at least , the queue is non-empty for all levels . This ensures that there are at most active timestamps at level .
Hence, by a union bound over all levels and time, with high probability, the total number of timestamps across all levels remains bounded by throughout the entire stream.
Rounding the Indyk’s p-stable Sketch and Difference Estimator
Our algorithm maintains only timestamps at the top level. However, each of these timestamps stores an instance of Indyk’s p-stable Sketch sketch, which uses bits, and the total space for the Difference Estimator sketches at each level is also . To reduce the overall space to , we apply the rounding technique from [16] to compress the sketch values.
Lemma 24 (Correctness of rounding Indyk’s p-stable Sketch ).
Let , and be a window, be the sketch matrix, , be the sketch vector after rounding procedure 2 with parameter .
Then with probability .
Proof.
The proof simply follows Lemma 21.
Setting the in Lemma 24 to be , we can store the rounded vector in space .
Next, we prove the correctness of rounding the Difference Estimator, for . The argument is the same as Lemma 24.
Lemma 25 (Correctness of rounding the Difference Estimator ).
Let , be 2 frequent vector, be the sketch matrix, , for , recall the way Difference Estimator estimate the difference between and is by calculate the mean of . Then the mean of only deviate from the original estimation with probability .
Thus, setting and , we can store the each Difference Estimator in space .
4.4 Nearly Optimal Estimation
Now we introduce our main result for estimation.
Theorem 26.
Let , for any fixed window , with probability , Algorithm 2 will give an approximation of , and use bits of space, more specifically, .
Let the query window be , and let be the smallest index that , and . First, we prove that our top level Strong Estimator gives a constant approximation. The proof can be easily seen from Lemma 16.
Lemma 27 (Constant factor partitions in top level).
With probability , and .
Proof.
As we use a Strong Estimator for . By Lemma 16, . So and .
Let be the event that the top level Strong Estimator gives a constant factor partition, and for the subroutine levels, all the instances of Strong Estimator satisfy the Strong Estimator property on window . In the subroutine level, we use Strong Estimator, so by a union bound, all the instances of Strong Estimator satisfy the Strong Estimator property in window with probability .
So by adjusting the constant for , with probability , will happen.
We now show an upper bound on the moment of each substream whose contribution is estimated by the difference estimator, i.e., the difference estimators are well-defined.
Lemma 28 (Upper bounds on splitting times).
Let . Conditioned on , we have that for each and all , either or .
Lemma 29 (Accuracy of difference estimators. Lemma A.3 [21]).
Let . Conditioned on the event in Lemma 28 holding, we have that for each and all ,
gives an additive approximation to with probability at least .
Lemma 30 (Geometric upper bounds on splitting times. Lemma A.4 [21]).
Let . Conditioned on the event in Lemma 28 holding, we have that for each and each that either or .
Lemma 31 (Geometric Lower bounds on splitting times).
Let , conditioned on , we have that for each and each that
Lemma 32 (Number of level difference estimators. Lemma A.6 [21]).
Let , conditioned on the Geometric Lower bounds on splitting times to hold (Lemma 31) , we have that for each , that for any .
We next bound the number of level difference estimators that can occur from the end of the previous level difference estimator to the time when the sliding window begins. We say a difference estimator is active if for the indices and defined in StitchSW. The active difference estimators in each level will be the algorithms whose output are subtracted from the initial rough estimate to form the final estimate of .
Lemma 33 (Number of active level difference estimators. Lemma A.7 [21]).
Lemma 34 (Correctness of sliding window algorithm).
For , Algorithm 2 outputs a -approximation to with probability .
Now we will prove the space bound.
Lemma 35.
Let be a constant , Algorithm 2 uses space bits.
5 Lower bounds
We consider the following communication problem, which is a generalization of the classic GreaterThan communication problem.
Problem 36.
In the problem, Alice receives a sequence . Bob receives an an index and a number Alice sends a one-way message to Bob, and Bob must decide if or if
Lemma 37.
Problem 36 requires communication to solve with probability.
This lower bound is known. For instance [7] applies it in their lower bounds as well. We supply a short proof in the appendix from the somewhat more standard Augmented Index problem.
Lemma 38.
Let and let be parameters satisfying the following:
Suppose that is a streaming algorithm that operates on sliding windows of size , and gives a multiplicative approximation to on any fixed window with probability, over the universe .
Then uses at least space.
Proof.
See the appendix of the full version.
Theorem 39.
Fix . Suppose that is a streaming algorithm that operates on a window of size , and outputs a approximation of on any fixed window with probability. Suppose that Then must use at least
space. In particular for constant and must use at least
space.
Proof.
The second term in the lower bound is shown by [5] in their Theorem 11 for general insertion-only streams.
References
- [1] Noga Alon, Yossi Matias, and Mario Szegedy. The space complexity of approximating the frequency moments. In Proceedings of the twenty-eighth annual ACM symposium on Theory of computing, pages 20–29, 1996. doi:10.1145/237814.237823.
- [2] Ziv Bar-Yossef, Thathachar S Jayram, Ravi Kumar, and D Sivakumar. An information statistics approach to data stream and communication complexity. Journal of Computer and System Sciences, 68(4):702–732, 2004. doi:10.1016/J.JCSS.2003.11.006.
- [3] Mihir Bellare and John Rompel. Randomness-efficient oblivious sampling. In Proceedings 35th Annual Symposium on Foundations of Computer Science, pages 276–287. IEEE, 1994. doi:10.1109/SFCS.1994.365687.
- [4] Jarosław Błasiok, Jian Ding, and Jelani Nelson. Continuous monitoring of norms in data streams. arXiv preprint arXiv:1704.06710, 2017.
- [5] Mark Braverman and Or Zamir. Optimality of frequency moment estimation. arXiv preprint arXiv:2411.02148, 2024. doi:10.48550/arXiv.2411.02148.
- [6] Vladimir Braverman, Stephen R Chestnut, Nikita Ivkin, Jelani Nelson, Zhengyu Wang, and David P Woodruff. Bptree: An heavy hitters algorithm using constant memory. In Proceedings of the 36th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, pages 361–376, 2017.
- [7] Vladimir Braverman, Elena Grigorescu, Harry Lang, David P Woodruff, and Samson Zhou. Nearly optimal distinct elements and heavy hitters on sliding windows. arXiv preprint arXiv:1805.00212, 2018. arXiv:1805.00212.
- [8] Vladimir Braverman and Rafail Ostrovsky. Smooth histograms for sliding windows. In 48th Annual IEEE Symposium on Foundations of Computer Science (FOCS’07), pages 283–293, 2007. doi:10.1109/FOCS.2007.55.
- [9] Vladimir Braverman and Rafail Ostrovsky. Smooth histograms for sliding windows. In 48th Annual IEEE Symposium on Foundations of Computer Science (FOCS’07), pages 283–293. IEEE, 2007. doi:10.1109/FOCS.2007.55.
- [10] Vladimir Braverman and Rafail Ostrovsky. Effective computations on sliding windows. SIAM Journal on Computing, 39(6):2113–2131, 2010. doi:10.1137/090749281.
- [11] Moses Charikar, Kevin Chen, and Martin Farach-Colton. Finding frequent items in data streams. In International Colloquium on Automata, Languages, and Programming, pages 693–703. Springer, 2002. doi:10.1007/3-540-45465-9_59.
- [12] Mayur Datar, Aristides Gionis, Piotr Indyk, and Rajeev Motwani. Maintaining stream statistics over sliding windows. SIAM journal on computing, 31(6):1794–1813, 2002. doi:10.1137/S0097539701398363.
- [13] Erik D Demaine, Alejandro López-Ortiz, and J Ian Munro. Frequency estimation of internet packet streams with limited space. In European Symposium on Algorithms, pages 348–360. Springer, 2002. doi:10.1007/3-540-45749-6_33.
- [14] Piotr Indyk. Stable distributions, pseudorandom generators, embeddings, and data stream computation. Journal of the ACM (JACM), 53(3):307–323, 2006. doi:10.1145/1147954.1147955.
- [15] Piotr Indyk and David Woodruff. Optimal approximations of the frequency moments of data streams. In Proceedings of the thirty-seventh annual ACM symposium on Theory of computing, pages 202–208, 2005. doi:10.1145/1060590.1060621.
- [16] Rajesh Jayaram and David P. Woodruff. Towards optimal moment estimation in streaming and distributed models. ACM Trans. Algorithms, 19(3), June 2023. doi:10.1145/3596494.
- [17] Hossein Jowhari, Mert Sağlam, and Gábor Tardos. Tight bounds for samplers, finding duplicates in streams, and related problems. In Proceedings of the Thirtieth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, PODS ’11, pages 49–58, New York, NY, USA, 2011. Association for Computing Machinery. doi:10.1145/1989284.1989289.
- [18] Daniel M Kane, Jelani Nelson, and David P Woodruff. On the exact space complexity of sketching and streaming small norms. In Proceedings of the twenty-first annual ACM-SIAM symposium on Discrete Algorithms, pages 1161–1178. SIAM, 2010. doi:10.1137/1.9781611973075.93.
- [19] James L. Jr. Nolan. Stable distributions. models for heavy tailed data, 2001. URL: https://api.semanticscholar.org/CorpusID:117487370.
- [20] Subhabrata Sen and Jia Wang. Analyzing peer-to-peer traffic across large networks. In Proceedings of the 2nd ACM SIGCOMM Workshop on Internet measurment, pages 137–150, 2002. doi:10.1145/637201.637222.
- [21] David P Woodruff and Samson Zhou. Tight bounds for adversarially robust streams and sliding windows via difference estimators. In 2021 IEEE 62nd Annual Symposium on Foundations of Computer Science (FOCS), pages 1183–1196. IEEE, 2022.
- [22] Vladimir M Zolotarev. One-dimensional stable distributions, volume 65. American Mathematical Soc., 1986.