Problem

Let D\mathcal{D} be an order domain with size dd, and f=(0,…,0)∈Ndf = (0, \ldots, 0) \in \mathbb{N}^d be the frequency vector initialized with all zeros. Suppose that there is a stream SS of nn elements updating ff as follows:

For each x∈Sx \in S do
\qquad f[x]←f[x]+1f[x] \leftarrow f[x] + 1.

When all updates in SS have arrived, we have that ∣S∣=∥f∥1=n|S| = \Vert f \Vert_1 = n.

We study the ranks of elements in D\mathcal{D}.

Definition. For x∈Dx \in \mathcal{D}, define the rank r(x)r(x) of xx to as

r(x)≐∑y<xf[y]. r(x) \doteq \sum_{y < x} f[y].

Approximate Rank Query. Given a parameter ϵ∈(0,1)\epsilon \in (0, 1), design a data structure which, for each x∈Dx \in \mathcal{D}, outputs an estimate r^(x)\hat r(x) of r(x)r(x), such that

r(x)−ϵ∥f∥1≤r^(x)≤r(x)+ϵ∥f∥1. r(x) - \epsilon \Vert f \Vert_1 \le \hat r(x) \le r(x) + \epsilon \Vert f \Vert_1.

MRL Sketch

Theorem (MRL Sketch). If the size of the stream ∣S∣=n|S| = n is given in advance, the MRL Sketch solves the approximate rank query with space usage

O(ϵ−1log⁡2(ϵn)). O \left( \epsilon^{-1} \log^2 (\epsilon n) \right).

Structure

The structure of the algorithm comprises a sequence of L+1L + 1 arrays A0,…ALA_0, \ldots A_L, each of size

k≐⌈ϵ−1(1+log⁡(ϵn))⌉even k \doteq \lceil \epsilon^{-1} \big( 1 + \log ( \epsilon n ) \big)\rceil_{even}

where ⌈⋅⌉even\lceil \cdot \rceil_{even} is the operation of rounding a real number up to nearest even integer.

It sets LL, the largest index of the arrays, to ⌈log⁡(n/k)⌉\lceil \log (n / k) \rceil. Therefore,

Lk≤⌈log⁡(ϵn)⌉ϵ−1(1+log⁡(ϵn))≤1+log⁡(ϵn)ϵ−1(1+log⁡(ϵn))≤ϵ. \begin{aligned} \frac{L}{k} \le \frac{ \lceil \log (\epsilon n) \rceil }{ \epsilon^{-1} \big( 1 + \log ( \epsilon n ) \big) } \le \frac{ 1 + \log ( \epsilon n) }{ \epsilon^{-1} \big( 1 + \log (\epsilon n) \big) } \le \epsilon. \end{aligned}

Insertion

The MRL sketch processes an insertion as follows.

Insert: x∈Dx \in \mathcal{D}.

  1. Insert xx into A0A_0;
  2. COMPRESS.

The algorithm COMPRESS inspects the arrays A0,…,AL−1A_0, \ldots, A_{L - 1} in increasing order. If an array AiA_i, reaches its capacity, the algorithm performs a compaction on AiA_i. In particular, it moves the odd-indexed elements of AiA_i to Ai+1A_{i + 1}, and then reset AiA_i to empty (by deleting all its elements). This may cause Ai+1A_{i + 1} to research its capacity, and trigger a sequence of compactions.

COMPRESS.

  1. i←0i \leftarrow 0;
  2. while i<Li < L and ∣Ai∣=k:|A_i| = k: // no empty buckets
  3. \qquad Sort AiA_i in increasing order.
  4. \qquad Move Ai[1],Ai[3],…,Ai[k−1]A_i[1], A_i[3], \ldots, A_i[k - 1] into Ai+1A_{i + 1}
  5. \qquad Delete all elements in AiA_i
  6. \qquad i←i+1i \leftarrow i + 1.

Suppose that each elements in array AiA_i (0≤i≤L0 \le i \le L) is associated with weight wi=2iw_i = 2^i. It is easy to prove, by induction on the size of nn, and on the number of inductions performed, the following invariant

Invariant. For 0≤i≤L0 \le i \le L, define wi=2iw_i = 2^i. Then

∑i=0Lwi⋅∣Ai∣=n. \sum_{ i = 0}^L w_i \cdot |A_i| = n.

Therefore, 2L∣AL∣=2⌈log⁡(n/k)⌉⋅∣AL∣≤n2^L |A_L| = 2^{ \lceil \log (n / k) \rceil } \cdot |A_L| \le n. Therefore, ∣AL∣≤k|A_L| \le k and ALA_L will never exceed its capacity.

Interpretation of Weights

The weights have another interpretation. Suppose that we associate each element inserted into A0A_0 with a set, which contains only the element itself. We will maintain these sets, such that

For each 0≤i≤L0 \le i \le L, and each v∈Aiv \in A_i, the set associated with vv has size wiw_i, and vv is the only element in the set that is kept in the arrays. Further, the sets associated with different elements in the arrays are disjoint.

Clearly this holds when an element is inserted into A0A_0. Now, suppose we are going to perform a compaction at an array AiA_i, for some 0≤i<L0 \le i < L. We delete half of the elements in AiA_i, and keep the rest of the elements. We can pair up the elements deleted and the ones kept one by one, and merge their associated sets. For each merged set, it contains wi+1w_{i + 1} elements, and only one element in the merge set is kept in the arrays. Hence, we can associate it with the only element kept.

The above discussion gives a new interpretation of the weights.

If an element is associated with weight wiw_i, it represents wiw_i unique elements in the original stream.

Query

Definition. For each i∈{0,…,L}i \in \{0, \ldots, L \}, and x∈Dx \in \mathcal{D}, let r(x,Ai)r(x, A_i) be the rank of xx in AiA_i, defined as

r(x,Ai)≐∣{y∈Ai:y<x}∣, r(x, A_i) \doteq | \{ y \in A_i : y < x \} |,

which is the number of elements in AiA_i that is strictly less than xx.

Given x∈Dx \in D, the MRL sketch returns an weighted sum of the ranks r(x,Ai)r(x, A_i), as an estimate of r(x)r(x):

r^(x)=∑i=0Lwi⋅r(x,Ai). \hat r(x) = \sum_{i = 0}^{L} w_i \cdot r(x, A_i).

Rank: x∈Dx \in \mathcal{D}

  1. r^(x)←0\hat r(x) \leftarrow 0;
  2. For i←0i \leftarrow 0 to LL do
  3. \qquad r^(x)←r^(x)+wi⋅r(x,Ai)\hat r(x) \leftarrow \hat r(x) + w_i \cdot r(x, A_i).

Error Analysis

Now we analyze the approximation error of r^(x)\hat r(x).

We illustrate the key idea of the analysis via an example. In the figure below, k=4k = 4. Before the compaction, A5A_5 contributes 25⋅r(4,A5)=25⋅22^5 \cdot r(4, A_5) = 2^5 \cdot 2 to the estimation of r^(4)\hat r(4), and 25⋅r(9,A5)=25⋅32^5 \cdot r(9, A_5) = 2^5 \cdot 3 to the estimation of r^(9)\hat r(9).

The compaction moves elements in the odd positions of A5A_5, namely 33 and 1010, to A6A_6. Then it deletes all elements in A5A_5.

After the compaction, A6A_6 contributes 26⋅r(4,A6)=26⋅12^6 \cdot r(4, A_6) = 2^6 \cdot 1 to the estimation of r^(4)\hat r(4), and 26⋅r(9,A6)=26⋅12^6 \cdot r(9, A_6) = 2^6 \cdot 1 to the estimation of r^(9)\hat r(9).

There is no error incurred to the estimation of r^(4)\hat r(4) at this compaction step, while the estimation error incurred to r^(9)\hat r(9) is −25-2^5 at this compaction step.

The above discussion leads to the following observations.

Observation. Let x∈Dx \in \mathcal{D} and 0≤i<L0 \le i < L. Denote Ai,Ai+1A_i, A_{i + 1} the arrays before the compaction and Ai′,Ai+1′A_i', A_{i + 1}' the ones after.

  1. If r(x,Ai)r(x, A_i) is even, then

    wi+1⋅r(x,Ai+1′)=wi+1⋅r(x,Ai+1)+wi⋅r(x,Ai), w_{i + 1} \cdot r(x, A_{i + 1}' ) = w_{i + 1} \cdot r(x, A_{i + 1} ) + w_{i} \cdot r(x, A_i),

    which implies that the compaction at AiA_i incurs no error to the estimation of r(x)r(x).

  2. If r(x,Ai)r(x, A_i) is odd, then

    wi+1⋅r(x,Ai+1′)+wi=wi+1⋅r(x,Ai+1)+wi⋅r(x,Ai). w_{i + 1} \cdot r(x, A_{i + 1}' ) + w_i = w_{i + 1} \cdot r(x, A_{i + 1} ) + w_{i} \cdot r(x, A_i).

    which implies that the compaction at AiA_i incurs an error of −2i-2^i to the estimation of r(x)r(x).

Let mim_i be the number of compactions performed at AiA_i. For each j<ij < i, each compaction at AjA_j discards k/2k / 2 elements and transfers only k/2k / 2 elements to Aj+1A_{j + 1}. Therefore, the number of elements that have ever been inserted into AiA_i is bounded by n/2in / 2^i, and mim_i is bounded by

mi≤n2i⋅k. m_i \le \frac{n}{ 2^i \cdot k}.

Given x∈Dx \in \mathcal{D}, let ηi,t\eta_{i, t} be the parity of r(x,Ai)r(x, A_i) just before the t(th)t^{(th)} compaction is performed on AiA_i. The estimation error Err(x)\mathbb{Err}(x) is given by

Err(x)=r(x)−r^(x)=∑i=0L−1∑t∈[mi]ηi,t⋅2i≤∑i=0L−1n2i⋅k⋅2i=n⋅Lk≤ϵn. \begin{aligned} \mathbb{Err}(x) &= r(x) - \hat r(x) \\ &= \sum_{i = 0}^{L - 1} \sum_{t \in [m_i] } \eta_{i, t} \cdot 2^i \\ &\le \sum_{i = 0}^{L - 1} \frac{n}{2^i \cdot k} \cdot 2^i \\ &= \frac{n \cdot L}{k} \\ &\le \epsilon n. \end{aligned}

The last inequality follows from that L/k≤ϵL / k \le \epsilon.

Basic KLL Sketch

In this section, we reduce the space usage from O(ϵ−1⋅log⁡2(ϵn))O \left( \epsilon^{-1} \cdot \log^2 (\epsilon n) \right) to

O(ϵ−1⋅ln⁡(1/δ)⋅log⁡ϵnlog⁡(1/δ)). O \left( \epsilon^{-1} \cdot \sqrt{ \ln (1 / \delta) } \cdot \log \frac{ \epsilon n }{ \sqrt{ \log (1 / \delta) } } \right).

The algorithm is a randomized one and has failure probability δ\delta.

The algorithm is similar to the MRL sketch, but sets k=2/ϵ⋅ln⁡2/δk = 2 / \epsilon \cdot \sqrt{ \ln 2 / \delta } and L=⌈log⁡(n/k)⌉L = \lceil \log (n / k) \rceil to achieve the space usage stated above. Besides, the compaction step is different.

Random Parity

Instead of always moving the odd-indexed elements to the next array, it chooses uniformly at random either the odd-indexed elements, or even-indexed elements. In particular, it replaces the line 4 of the COMPRESS algorithm with the following lines:

  1. Flip an unbiased coin;
  2. If the coin turns out head:
  3. \qquad Move Ai[1],Ai[3],…,Ai[k−1]A_i[1], A_i[3], \ldots, A_i[k - 1] into Ai+1A_{i + 1};
  4. Else:
  5. \qquad Move Ai[0],Ai[2],…,Ai[k−2]A_i[0], A_i[2], \ldots, A_i[k - 2] into Ai+1A_{i + 1};

Unbiased Estimation

For each x∈Dx \in \mathcal{D} and 0≤i<L0 \le i < L, if r(x,Ai)r(x, A_i) is even, then there is no error introduced after the compaction on AiA_i. If r(x,Ai)r(x, A_i) is odd, then the error introduced is either 2i2^i or −2i-2^i, both with probability 1/21 / 2. Hence, the expected error is always 00.

The estimation error Err(x)\mathbb{Err}(x) is given by

Err(x)=∑i=0L−1∑t∈[mi]ηi,t⋅σi,t⋅2i, \begin{aligned} \mathbb{Err}(x) &= \sum_{i = 0}^{L - 1} \sum_{t \in [m_i] } \eta_{i, t} \cdot \sigma_{i, t} \cdot 2^i, \end{aligned}

where σi,t∈{−1,1}\sigma_{i, t} \in \{-1, 1\} are Rademacher random variables.

Clearly, we have that

E[Err(x)]=0. \begin{aligned} \mathbb{E} \left[ \mathbb{Err}(x) \right] = 0. \end{aligned}

Confidence Interval of the Estimation Error

However, the random variables ηi,t⋅σi,t⋅2i\eta_{i, t} \cdot \sigma_{i, t} \cdot 2^i are not independent, as the values of ηi,t\eta_{i, t} depends on previous compressions.

Instead of using the Hoeffding's inequality for independent random variables, we resort to a martingale concentration inequality.

Martingale Difference Sequence

Let m=∑i=0L−1mim = \sum_{ i = 0}^{L - 1} m_i be the total number of compaction at the arrays. For fixed nn and kk, mm is a deterministic number (even without knowing the elements in SS). Further, for each t∈[m]t \in [m], the array at which the tt-th compaction is performed is also deterministic. Denote at∈[0,…,L−1]a_t \in [0, \ldots, L - 1] the index of the corresponding array, and let ct≐2atc_t \doteq 2^{ a_t }, which is a deterministic number since ata_t is deterministic. It holds that

∑t∈[m]ct2=∑i=0L−1∑t∈[mi](2i)2≤∑i=0L−1n2i⋅k⋅(2i)2≤nk⋅2L≤2⋅(nk)2. \sum_{t \in [m] } c_t^2 = \sum_{i = 0}^{L - 1} \sum_{t \in [m_i] } \big( 2^i \big)^2 \le \sum_{i = 0}^{L - 1} \frac{n}{2^i \cdot k} \cdot \big( 2^i \big)^2 \le \frac{n}{k} \cdot 2^L \le 2 \cdot \left( \frac{n}{k} \right)^2.

The last inequality follows since L=⌈log⁡(n/k)⌉L = \lceil \log (n / k) \rceil.

For each t∈[m]t \in [m], define the random variable Xt∈{−ct,0,ct}X_t \in \{-c_t, 0, c_t\}, such that

  1. If rank(x,Aat)rank(x, A_{a_t}) is even, then Pr⁡[Xt=0]=1\Pr[ X_t = 0] = 1.
  2. If rank(x,Aat)rank(x, A_{a_t}) is odd, then Pr⁡[Xt=−ct]=Pr⁡[Xt=ct]=1/2\Pr[ X_t = -c_t ] = \Pr[ X_t = c_t ] = 1 / 2

The XtX_t are not independent random variables, since for t>1t > 1, when the tt-th compaction happens at the ata_t-th array AatA_{a_t}, the rank of xx at this array depends on the previous compressions. However, the conditional expectation of XtX_t is always 00:

E[Xt∣Xt−1,…,X1]=0. \mathbb{E} [ X_t \mid X_{t - 1}, \ldots, X_1 ] = 0.

Hence, X1,…,XmX_1, \ldots, X_m is a martingale difference sequence.

Theorem.([1]) Let c1,…,cmc_1, \ldots, c_m be constants, and let X1,…,XmX_1, \ldots, X_m be a martingale difference sequence with ∣Xt∣≤ct|X_t| \le c_t for each tt. Then for any λ≥0\lambda \ge 0,

Pr⁡[∣∑t∈[m]Xt∣≥λ]≤2⋅exp⁡(−λ22⋅∑t∈[m]ct2). { \small \Pr \left[ \left| \sum_{t \in [m] } X_t \right| \ge \lambda \right] \le 2 \cdot \exp \left( - \frac{ \lambda^2 }{ 2 \cdot \sum_{ t \in [m] } c_t^2 }\right). }

Choosing kk

It follows that with probability at least 1−δ1 - \delta, it holds that

∣∑t∈[m]Xt∣≤2⋅(∑t∈[m]ct2)⋅ln⁡2δ≤2⋅nk⋅2L⋅ln⁡2δ≤2⋅(nk)2⋅ln⁡2δ \left| \sum_{t \in [m] } X_t \right| \le \sqrt{ 2 \cdot \left( \sum_{t \in [m] } c_t^2 \right) \cdot \ln \frac{2}{\delta } } \le \sqrt{ 2 \cdot \frac{n}{k} \cdot 2^L \cdot \ln \frac{2}{\delta } } \le 2 \cdot \sqrt{ \left( \frac{n}{k} \right)^2 \cdot \ln \frac{2}{\delta } }

Setting k=⌈2/ϵ⋅ln⁡2/δ⌉evenk = \Big\lceil 2 / \epsilon \cdot \sqrt{ \ln 2 / \delta } \Big\rceil_{even}, this error is bounded by ϵ⋅n\epsilon \cdot n.

The total space usage is therefore

k⋅L∈O(k⋅log⁡nk)⊂O(1ϵ⋅ln⁡1δ⋅log⁡ϵ⋅nln⁡1/δ). k \cdot L \in O \left( k \cdot \log \frac{n}{k} \right) \subset O \left( \frac{1}{\epsilon} \cdot \sqrt{ \ln \frac{1}{\delta} } \cdot \log \frac{\epsilon \cdot n }{ \sqrt{ \ln 1 / \delta } } \right).

Remark. It is kind of amazing that the size of kk does not depends on nn. On the other hand, even though the size of LL depends on nn, we can still apply the algorithm when we don't know the value of nn in advance. We can create new arrays on the fly. In particular, if the array with the largest index exceeds its capacity, we perform compaction at it and create a new array. Note the we don't perform compaction at that array, when it reaches its capacity. The entire analysis still holds.

Improved KLL Sketch

In this section, we improve the space usage to

O(1ϵ⋅ln⁡1δ+log⁡ϵ⋅nln⁡1/δ). O \left( \frac{1}{\epsilon} \cdot \sqrt{ \ln \frac{1}{\delta} } + \log \frac{\epsilon \cdot n }{ \sqrt{ \ln 1 / \delta } } \right).

Compared to the basic KLL, the improved algorithm allows the capacities of the arrays to vary. Denote the largest index of the arrays as LL. It and maintains the following invariant:

  • For each 0≤i≤L0 \le i \le L, the array AL−iA_{L - i} has capacity ⌈αi⋅k⌉even\lceil \alpha^i \cdot k \rceil_{even}, where α∈(0.5,1)\alpha \in (0.5, 1) is a parameter chosen by the algorithm.

The algorithm sets k=⌈2/ϵ⋅1/(2α−1)⋅ln⁡2/δ⌉evenk = \Big\lceil 2 / \epsilon \cdot \sqrt{ 1 / (2 \alpha - 1 ) \cdot \ln 2 / \delta } \Big\rceil_{even}. When nn elements arrive, at least one compaction is performed at AL−1A_{L - 1}, as otherwise ALA_L would be not created. When the first compaction is performed at AL−1A_{L - 1}, it has capacity kk. As each element in AL−1A_{L - 1} represents 2L−12^{L - 1} unique elements in the original stream,

k⋅2L−1≤n  ⟹  2L−1≤nk, and  L≤⌈2log⁡nk⌉. k \cdot 2^{L - 1} \le n \implies 2^{L - 1} \le \frac{n}{k},\, \text{and }\, L \le \left\lceil 2 \log \frac{n}{k} \right\rceil.

It follows that the total space usage is bounded by

k⋅∑i≥0αi+2⋅L∈O(1ϵ⋅11−α⋅12α−1⋅ln⁡1δ+log⁡ϵ⋅n⋅2α−1ln⁡1/δ). k \cdot \sum_{ i \ge 0} \alpha^i + 2 \cdot L \in O \left( \frac{1}{\epsilon} \cdot \frac{1}{1 - \alpha}\cdot \sqrt{ \frac{1}{2 \alpha - 1} \cdot \ln \frac{1}{\delta} } + \log \frac{\epsilon \cdot n \cdot \sqrt{2 \alpha - 1} }{ \sqrt{ \ln 1 / \delta } } \right).

If we set, e.g., α=2/3\alpha = 2 / 3, then this is

O(1ϵ⋅ln⁡1δ+log⁡ϵ⋅nln⁡1/δ). O \left( \frac{1}{\epsilon} \cdot \sqrt{ \ln \frac{1}{\delta} } + \log \frac{\epsilon \cdot n }{ \sqrt{ \ln 1 / \delta } } \right).

Algorithm

Initially, L=0L = 0 and the algorithm creates a single array A0A_0 with capacity kk. When ALA_L reaches or exceeds its capacity, the algorithm increases LL and creates a new array. The new algorithm COMPRESS is as follows.

COMPRESS.

  1. i←0i \leftarrow 0
  2. while ∣Ai∣≥⌈αL−i⋅k⌉even|A_i| \ge \lceil \alpha^{L - i} \cdot k \rceil_{even} // no empty buckets
  3. \qquad If i=Li = L then
  4. \qquad\qquad L←L+1L \leftarrow L + 1
  5. \qquad\qquad Create a new array ALA_L
  6. \qquad Sort AiA_i in increasing order
  7. \qquad Flip an unbiased coin
  8. \qquad If AiA_i contains odd number of elements then
  9. \qquad \qquad E←E \leftarrow the element at the back of AA
  10. \qquad \qquad delete EE from AA
  11. \qquad Else
  12. \qquad \qquad E←E \leftarrow null
  13. \qquad If the coin turns out head then
  14. \qquad \qquad Move odd index elements of AiA_i to Ai+1A_{ i + 1 }
  15. \qquad Else:
  16. \qquad \qquad Move even index elements of AiA_i to Ai+1A_{i + 1}
  17. \qquad Delete all elements in AiA_i
  18. \qquad If E≠E \neq null then
  19. \qquad \qquad Put EE back into AiA_i
  20. \qquad i←i+1i \leftarrow i + 1

Analysis

Maintaining the Invariant

Lemma. The invariant is maintained.

Proof. We prove this by induction. Initially, L=0L = 0 and A0A_0 has capacity kk. If A0A_0 has not reaches its capacity, the invariant holds trivially.

Now, suppose that the invariant holds before the algorithm COMPRESS.

If LL is not increased and no new array is created by the algorithm, i.e., the while loop of the algorithm stops for i≤Li \le L, then the invariant still holds.

If LL is increased and new arrays are created, then when the algorithm COMPRESS stops, compactions have been performed for all arrays except the one with highest index. Hence, $ 0 \le |A_j| \le 1 < \lceil \alpha^i \cdot k \rceil_{even}. $ Finally, when while loop stops, it holds that i=Li = L. The stopping condition implies that ∣AL∣<⌈α0⋅k⌉even=k|A_L| < \lceil \alpha^0 \cdot k \rceil_{even} = k.

□\square

Question to ponder: Prove that at most one new array can be created by COMPRESS each time it is invoked.

Bounding the Number of Compaction

Lemma. When the algorithms stops, for each i∈[L]i \in [L], the number of compaction performed at the array AL−iA_{L - i} is bounded by (4/α)i(4 / \alpha)^i.

Proof. For each i∈[L]i \in [L], when a compaction is performed at AL−iA_{L - i}, at least ⌈αi⋅k⌉even\lceil \alpha^i \cdot k \rceil_{even} elements are removed from it. As each element in AL−iA_{L - i} represents 2L−i2^{L - i} elements in the original stream, it holds that

mL−i≤n2L−i⋅⌈αi⋅k⌉even≤n2L−i⋅αi⋅k m_{L - i} \le \frac{ n }{ 2^{L - i} \cdot \lceil \alpha^i \cdot k \rceil_{even} } \le \frac{ n }{ 2^{L - i} \cdot \alpha^i \cdot k }

□\square

Finally, we discuss the estimation error of an element. For fixed nn, the number of compactions performed, as well as the order of the compactions performed are deterministic. Using the notations in the previous section, we have

∑t∈[m]ct2=∑i∈[L]mL−i⋅(2L−i)2≤∑i∈[L]n2L−i⋅αi⋅k⋅(2L−i)2≤∑i∈[L]nαi⋅k⋅(2L−i)=2L⋅nk⋅∑i∈[L]1(2⋅α)i. \begin{aligned} \sum_{t \in [m] } c_t^2 &= \sum_{i \in [L] } m_{L - i} \cdot \big( 2^{L - i} \big)^2 \\ &\le \sum_{i \in [L] } \frac{ n }{ 2^{L - i} \cdot \alpha^i \cdot k } \cdot \big( 2^{L - i} \big)^2 \\ &\le \sum_{i \in [L] } \frac{ n }{ \alpha^i \cdot k } \cdot \big( 2^{L - i} \big) \\ &= 2^L \cdot \frac{n}{k} \cdot \sum_{i \in [L] } \frac{ 1 }{ (2 \cdot \alpha)^i }. \end{aligned}

Using that 2L−1≤nk2^{L - 1} \le \frac{n}{k}, and that

∑i∈[L]1(2⋅α)i≤∑i≥11(2⋅α)i=12α⋅11−1/(2α)=12α−1, \sum_{i \in [L] } \frac{ 1 }{ (2 \cdot \alpha)^i } \le \sum_{i \ge 1 } \frac{ 1 }{ (2 \cdot \alpha)^i } = \frac{1}{2 \alpha} \cdot \frac{1}{1 - 1 / (2 \alpha) } = \frac{1}{ 2 \alpha - 1 },

we see

∑t∈[m]ct2≤2⋅(nk)2⋅12α−1. \sum_{t \in [m] } c_t^2 \le 2 \cdot \left( \frac{n}{k} \right)^2 \cdot \frac{1}{2 \alpha - 1}.

It follows that with probability at least 1−δ1 - \delta, it holds that

∣∑t∈[m]Xt∣≤2⋅(∑t∈[m]ct2)⋅ln⁡2δ≤2⋅2⋅(nk)2⋅12α−1⋅ln⁡2δ≤2⋅(nk)2⋅12α−1⋅ln⁡2δ \begin{aligned} \left| \sum_{t \in [m] } X_t \right| &\le \sqrt{ 2 \cdot \left( \sum_{t \in [m] } c_t^2 \right) \cdot \ln \frac{2}{\delta } } \\ &\le \sqrt{ 2 \cdot 2 \cdot \left( \frac{n}{k} \right)^2 \cdot \frac{1}{2 \alpha - 1} \cdot \ln \frac{2}{\delta } } \\ &\le 2 \cdot \sqrt{ \left( \frac{n}{k} \right)^2 \cdot \frac{1}{2 \alpha - 1} \cdot \ln \frac{2}{\delta } } \end{aligned}

Setting k=⌈2/ϵ⋅12α−1⋅ln⁡2/δ⌉evenk = \Big\lceil 2 / \epsilon \cdot \sqrt{ \frac{1}{2 \alpha - 1} \cdot \ln 2 / \delta } \Big\rceil_{even}, this error is bounded by ϵ⋅n\epsilon \cdot n.

Reference

[1] C. McDiarmid, “Concentration,” in Probabilistic Methods for Algorithmic Discrete Mathematics, M. Habib, C. McDiarmid, J. Ramirez-Alfonsin, and B. Reed, Eds. Berlin, Heidelberg: Springer Berlin Heidelberg, 1998, pp. 195–248.

[2] Z. Karnin, K. Lang, and E. Liberty, “Optimal Quantile Approximation in Streams,” arXiv:1603.05346 [cs], Apr. 2016