What a bound is

The pass that was never a parameter

One pass is the streaming model's defining restriction, and this collection has enforced it by making a second read throw. A prohibition cannot be swept. Turn it into a dial and the first thing it says is that a second pass turns eighteen candidate heavy hitters, six of them wrong, into twelve that are exactly right — for 3,680 bits carried across the boundary and no extra space at all.

Every summary in this collection is fed through a wrapper whose second iteration throws. The message names the model rather than the mechanism, because the failure it catches is conceptual: an algorithm allowed a second pass is not a streaming algorithm, and its space bound is a statement about nothing.

That enforcement is right and it has been in place since the field opened. What it is not is a parameter.

Every interesting bound in this area is stated in two quantities — passes and space — because they trade against each other. A restriction fixed at one cannot be swept, cannot be plotted, and cannot be traded. So the wrapper now takes a number: a stream may be read exactly pp times, and the p+1p+1-st read throws with the allowance in the message.

What crosses a boundary

The moment a second pass exists, a question appears that a one-pass model does not have: what does the algorithm keep between them?

The answer cannot be “whatever it happens to have in memory”, because that is unbounded and the whole subject is bounded memory. A pp-pass bound in space ss is a statement about the state that survives a pass boundary — that is the quantity the lower bounds are about, and it is the quantity an implementation is free to lie about if nobody asks.

So the carry is declared and then enforced, and the enforcement is what makes the numbers mean anything. Between passes the algorithm is reset() — every field wiped — and rebuilt with restore() from its own declared carry and nothing else. A procedure that reports thirty-two bits and quietly keeps a hash map does not produce a slightly optimistic number; it produces a wrong answer at the next pass and stops.

What crosses a boundary, against what is held during a pass — radix selection on uniform dataExact selection of the 0.5 quantile of 32,768 values. The outer bar is the peak state during a pass and the inner one is what the algorithm declared and carried across the boundary after it. The carry is small and nearly flat — an interval, a running count, and for the sampled rule a set of split points — while the working state falls by a factor of 37 across the sweep. A bound stated in passes and space is a statement about the carry; a memory budget is a statement about the working peak; and the two are different by up to 122 times here. The carry is enforced rather than believed: between passes the algorithm's state is wiped and rebuilt from the carry alone, so a procedure keeping something it did not declare returns a wrong answer rather than a flattering number. The horizontal scale is logarithmic.2 passes11,712 held96 carried3 passes2,112 held96 carried4 passes960 held96 carried5 passes640 held96 carried6 passes448 held96 carried7 passes384 held96 carried9 passes320 held96 carriedheld during a passcarried across the boundaryevery run exact · the carry is enforced96 bits at least
Fig. 1 The two quantities, and they are not the same one. The outer bar is the peak state during a pass; the inner one is what the algorithm declared and carried across the boundary after it. A bound in passes and space is about the inner bar; a memory budget is about the outer one.

This is the same device as the model enforcement in the essay on turnstiles and the text withholding in the self-index field, applied to the assumption neither covers: that a pass boundary is a moment at which everything not written down is gone.

It is not decoration. The check that keeps it honest is an algorithm built to cheat — one that keeps the exact count of every key in a map and declares a carry of nothing — and the requirement is that it comes back with the map gone. A second version, with the candidate list struck out of a real algorithm’s carry, must return no answer at all rather than the right one.

What a second pass buys

The canonical case, and it is the cleanest statement of a pass’s value this collection has.

A Misra-Gries summary with kk counters over a stream, asked for every key above ϕ\phi of it. Its guarantee is that no heavy hitter is missing from its table. It guarantees nothing about the rest, and its counts are lower bounds — so a counter sitting just under the threshold might be a heavy hitter that was decremented, or a light key that was not.

Nothing in the summary decides which. That is not a limitation of the reading; the information is not there. The shortfall is bounded by n/(k+1)n/(k+1) and it is not known key by key.

One pass gives 18 candidates of which 5 are wrong; two give 13 and none areA Misra-Gries summary with 128 counters over 32,768 arrivals, asked for every key above 0.01 of the stream. Its guarantee is that no heavy hitter is missing from its table; it guarantees nothing about the rest, and its counts are lower bounds, so a counter sitting just under the threshold might be a heavy hitter that was decremented or a light key that was not. Nothing in the summary decides which. A second pass decides it exactly: carry the 128 candidate keys across the boundary — 1,376 bits — and count only those. There are 13 genuinely heavy keys; the one-pass answer reports 18 and 5 of them are not heavy. The shaded cells are those, and the second pass costs one more read of the data and no more space.above 0.01 of the stream · 13 really areone pass: 18 candidatestwo passes: 13 keys, exactly the heavy ones123456789101112131415161718128 counters · carry 1,376 bits5 of 18 spurious
Fig. 2 The one-pass answer: eighteen keys, of which twelve are genuinely above the threshold and six are not. There is no way to tell them apart from the summary, and the six shaded cells are what a second pass removes.

A second pass settles it exactly. Carry the candidate keys across the boundary, count only those, and report the ones that clear the threshold. The result is exact — no false positives and no misses — and the cost is:

one pass two passes
keys reported 18 12
of which not heavy 6 0
heavy keys missed 0 0
peak state 8,192 bits 8,192 bits
carried across 3,680 bits

The same space, one more read of the data, and the answer goes from these eighteen contain the twelve to these are the twelve.

The carry is the interesting number. It is kk keys and a count — 3,680 bits at k=128k = 128 — which is smaller than the summary that produced it, because the counts can be thrown away. Only the identities matter; the counts are about to be recomputed exactly.

What the carry is made of

Three algorithms in these essays carry state across a boundary, and the three carries are worth putting side by side because they are different kinds of object.

A candidate set. The heavy-hitter procedure carries kk keys and the stream length: identities and one number. Nothing about the first pass’s counts survives, because the second pass is about to compute them exactly. That is the cheapest kind of carry — an index into the data rather than a summary of it.

An interval. The selection procedure carries two values and a count of what is already below the interval: ninety-six bits, at every pass count and every problem size. The whole result of a counting pass is compressed into “the answer is between here and here, and this many are below”. That is the cheapest carry there is, and it is the reason the multi-pass selection bound is about the working state rather than about the carry.

And a set of split points, when the split rule is data-dependent. Order statistics of a sample, carried so the next pass can count against them. That is the only carry here that grows with the parameter, and it is what an adaptive rule costs at the boundary as well as in passes.

The pattern across all three: a carry is small when the next pass can recompute what it needs and only has to be told where to look. It is large when the next pass needs a summary of what has gone before. Every multi-pass algorithm that is worth its extra read is of the first kind, and stating the carry separately is what makes the difference visible.

The precondition, which is a property of the summary

The procedure is often described as “one pass to find candidates, one to verify”, and stated that way it is wrong.

The candidate set is a superset of the heavy hitters only when kk is large enough. Misra-Gries’s guarantee is that any key occurring more than n/(k+1)n/(k+1) times is in the table, so a threshold of ϕn\phi n needs k+11/ϕk + 1 \ge 1/\phi. Below that, keys above the threshold can be absent from the table, and the second pass counts a candidate set that does not contain them.

Measured, at ϕ=0.01\phi = 0.01 on a stream with twelve genuinely heavy keys:

counters candidates after one pass wrong ones after two passes heavy keys missed
25 7 5
128 18 6 12 0
200 14 2 12 0
256 13 1 12 0

The first row is the failure mode that looks most like success. Twenty-five counters is a quarter of what the guarantee needs; the second pass is still exact, it is still fast, it returns seven keys and every one of them really is heavy. The output has no false positives and it is missing five answers, and nothing in it says so — the counts are exact, the threshold is exact, and there is no signal anywhere that the candidate set was not a superset.

Both halves are asserted. The two-pass answer at sufficient kk must have no false positives and no misses; the two-pass answer at insufficient kk must miss something, because an assertion that only checked the good case would leave the precondition looking decorative.

One pass gives 14 candidates of which 1 are wrong; two give 13 and none areA Misra-Gries summary with 200 counters over 32,768 arrivals, asked for every key above 0.01 of the stream. Its guarantee is that no heavy hitter is missing from its table; it guarantees nothing about the rest, and its counts are lower bounds, so a counter sitting just under the threshold might be a heavy hitter that was decremented or a light key that was not. Nothing in the summary decides which. A second pass decides it exactly: carry the 200 candidate keys across the boundary — 5,376 bits — and count only those. There are 13 genuinely heavy keys; the one-pass answer reports 14 and 1 of them are not heavy. The shaded cells are those, and the second pass costs one more read of the data and no more space.above 0.01 of the stream · 13 really areone pass: 14 candidatestwo passes: 13 keys, exactly the heavy ones1234567891011121314200 counters · carry 5,376 bits1 of 14 spurious
Fig. 3 The same procedure with more counters. The candidate set is tighter — fourteen rather than eighteen — so the second pass has less to do, and the answer it produces is the same twelve. More counters buys a smaller carry rather than a better answer, which is the reverse of what more counters usually buys.

Why the first pass narrows the second

The two passes are doing different things and it is worth naming what each contributes, because “verify” undersells the first one.

The second pass on its own — counting every key exactly — needs a counter per distinct key, which on this stream is 2,048 of them and 131,072 bits. That is not a summary; it is the exact structure the whole field exists to avoid.

The first pass’s contribution is that it bounds what the second pass has to be about. It reduces the universe from every key that occurred to kk candidates, and it does so in the space the streaming model allows. The second pass is then exact over a small universe, and small is what makes it fit.

That is the shape of nearly every multi-pass algorithm: an early pass narrows a candidate set, a later pass is exact over the narrowed set, and the space bound is set by how much narrowing the earlier passes managed. The essay on selection takes it to its limit — narrowing an interval instead of a key set, and doing it p1p-1 times.

Equal-width narrowing on uniform data: 5 passes to an exact answerThe interval that still might contain the 0.5 quantile of 32,768 values drawn from [0, 1,048,576), pass by pass. Each bar is the surviving range as a fraction of the universe and the number after it is how many of the 32,768 values are still inside it. The cuts are equal-width and need no knowledge of the data at all, so every pass narrows the RANGE by 9 — and on data spread evenly that narrows the COUNT by 9 too. The last pass keeps whatever is left and sorts it — 3 values, 640 bits — and that is the peak state of the whole run.pass 1 — count3,685 insidepass 2 — count457 insidepass 3 — count40 insidepass 4 — count3 insidepass 5 — keep3 insidethe whole universe32,768 values in [0, 1,048,576) · radix rule · answer 526,0565 passes · splits 9 · exact answer required640 bits at peak
Fig. 4 The same idea on a different question. The interval that might contain the median, pass by pass, with the number of values still inside it. The last pass keeps what is left and is exact over it, and the size of that remainder is the peak state of the whole run.

What the model becomes

Turning the restriction into a dial changes what the field’s bounds are statements about, and it is worth saying precisely what.

A one-pass space bound is a special case. Everything in this collection’s streaming field is p=1p = 1, and every one of those bounds remains exactly what it was. What changes is that they are now points on a curve rather than the whole story.

And several of the results become sharper. The exact distinct-count floor of log2(uu/2)\log_2\binom{u}{u/2} bits, and the window floor of exactly WW bits, are both one-pass arguments — the pigeonhole is over the states an algorithm can be in after reading a prefix, and it says nothing about an algorithm allowed to read the prefix again. Neither bound survives a second pass, and the essay on the selection floor is about exactly that gap.

Bits of state an exact distinct-counter needs, universe 8 to 20The middle line is log₂ C(u, u/2), the exact floor: a one-pass algorithm that answers the distinct count exactly must reach a different memory state for every half-sized subset of the universe, because two subsets sharing a state give the same answer after one more key is appended and their true answers differ. The upper line is the u-bit bitmap that achieves it. The lower line is ⌈log₂(u+1)⌉, the space a plain counter takes — always below the floor, which is why no plain counter is exact. At u = 12 the floor is 9.85 bits, and a candidate holding 8 was run over all 924 subsets: two of them reached the same state, and appending one key that is in one and not the other leaves answers of 6 and 7 that it cannot tell apart.011228101214161820universe size ubits of statea u-bit bitmaplog₂ C(u, u/2)⌈log₂(u+1)⌉, a counterat u = 12: 924 subsets, 8 bitstwo collide → answers 6 and 7floor computed exactly · collision found by exhaustion at u = 12floor 9.85 bits
Fig. 5 One of those one-pass floors, from earlier in this field. Every argument of this shape is about the states reachable after a prefix, and every one of them is silent about what a second read of that prefix would allow.

And the estimate-versus-exact axis moves. Nearly every structure in this field trades exactness for space. Multi-pass algorithms trade reads for space and keep exactness, which is a different bargain and is available whenever the data is on a disk rather than on a wire. The two are not alternatives so much as different columns in the same table, and the field has only ever had one of them.

Peak state against passes, for two splitting rules on two distributionsExact selection of the 0.5 quantile of 32,768 values, in p passes, with the state measured at its peak during the run. Every point is an exact answer — a run that returned anything else stops the build — so the vertical axis is the price of exactness rather than a price paid for being approximately right. The line at the top is what one pass costs: 1,048,576 bits, because an exact one-pass selector has to keep the stream, and the floor under that is a counting argument this collection performs rather than quotes. The equal-width rule needs no knowledge of the data and gets 37 times smaller as passes are added — on data spread evenly. On a heavy tail it collapses, because an equal-width cut of a range containing almost no data narrows the range and not the count; the sampled rule, which spends half its passes finding out where the data is, is barely affected. Both axes are logarithmic.10³10⁴10⁵10⁶passes over the datapeak bits of stateone pass, exact: 1,048,576 bitsradix, uniformsample, uniformradix, paretosample, paretoevery point exact · 32,768 values320 bits at best
Fig. 6 The other column, drawn. Exact selection of a median, in p passes, with the peak state measured. Every point is an exact answer and the vertical axis is the price of exactness.

What a pass costs

Nothing here charges for a pass, and that is a deliberate omission with a consequence.

A pass over data on a disk is a sequential read, and this collection has a field about what that costs: the external-memory model counts block transfers, and a pass is n/Bn/B of them. Two passes is twice that, and on a large enough dataset the second read is the dominant cost of the whole computation. A pass over data on a wire does not exist at all — the wire has moved on.

So the right way to read every plate in these three essays is: passes and space are being traded, and the exchange rate is left to the reader, because it depends on where the data is. What can be said without knowing that is which points are on the frontier, and that is what the plates draw.

What crosses a boundary, against what is held during a pass — sample selection on uniform dataExact selection of the 0.5 quantile of 32,768 values. The outer bar is the peak state during a pass and the inner one is what the algorithm declared and carried across the boundary after it. The carry is small and nearly flat — an interval, a running count, and for the sampled rule a set of split points — while the working state falls by a factor of 18 across the sweep. A bound stated in passes and space is a statement about the carry; a memory budget is a statement about the working peak; and the two are different by up to 2 times here. The carry is enforced rather than believed: between passes the algorithm's state is wiped and rebuilt from the carry alone, so a procedure keeping something it did not declare returns a wrong answer rather than a flattering number. The horizontal scale is logarithmic.3 passes12,352 held5,920 carried5 passes2,272 held1,120 carried7 passes1,024 held544 carried9 passes704 held384 carriedheld during a passcarried across the boundaryevery run exact · the carry is enforced384 bits at least
Fig. 7 The carry for an algorithm whose split points are data-dependent, which has to carry them: an interval, a count, and a set of order statistics. It is larger than the deterministic version’s carry by a factor of the split count, and it is still far smaller than what is held during a pass.

Two passes is not the same as twice the space

It is worth checking whether the second pass is doing something a bigger summary could have done instead, because if it is, the resource is not new.

It is not, and the arithmetic is worth doing. A key is reported when its count plus the shortfall bound clears the threshold, because the count is a lower bound and the structure has to be conservative. So eliminating false positives means driving n/(k+1)n/(k+1) below the gap between the threshold and the nearest non-heavy key’s true count.

On this stream the threshold is 400, the twelfth heavy key has 414 arrivals, and the heaviest non-heavy key has 394. The gap is six. Six is n/(k+1)n/(k+1) at k=6,666k = 6{,}666, and measured, the false positive disappears at k=6,667k = 6{,}667 and not before:

counters bits reported of which wrong
256 16,384 13 1
1,024 65,536 13 1
4,096 262,144 13 1
6,667 426,688 12 0

Four hundred and twenty-six thousand bits, against eight thousand and one more read: a factor of fifty-two. And the structure at that point holds more counters than the stream has distinct keys — 6,667 against 3,127 — so it is not a summary at all any more, it is the exact answer with a redundant bound attached.

No amount of state makes a one-pass Misra-Gries certain about a key near the threshold, short of becoming the exact structure. The shortfall bound falls but never reaches zero while any decrement has happened, and how close a non-heavy key sits to the threshold is a property of the data that no parameter can anticipate. The second pass gives certainty, which is a different thing from precision, and the one-pass model has no price for it at all.

That is the general reason passes are worth having as a separate axis rather than being folded into space. They buy a kind of answer, not a quantity of accuracy.

Only the uncertain candidates need carrying

The procedure as described carries every key in the table and re-counts all of them. It need not, and the reduction comes from a number the first pass already has.

Misra-Gries’s counts are short by at most DD, the number of decrement steps performed — a quantity the structure can tally as it runs, for the price of one integer. With it in hand, every candidate falls into one of three classes:

  • certainly heavy — its count already exceeds the threshold, and the true count is at least the count;
  • certainly not — its count plus DD is still below the threshold, and the true count is at most that;
  • uncertain — its bracket straddles the threshold.

Only the third class needs a second pass. The first two are settled by the first pass with no further reading of anything, and the answer for them is exact rather than probable.

That shrinks the carry from kk keys to however many sit within DD of the threshold, which on a skewed stream is a small number — the heavy keys are heavy by a wide margin and the light ones are light by a wider one, and only the handful clustered around the boundary are in doubt. On the stream measured here the threshold is 400 and the crowd near it is thin, so most of the eighteen candidates are decided before the second pass begins.

The second pass is therefore not a verification of the candidate set; it is a resolution of the boundary, and the boundary is the only part of the answer the first pass was uncertain about.

Two consequences worth having. The carry number quoted above — 3,680 bits — is an upper bound rather than the cost, and the actual cost depends on how many keys sit near the threshold, which is a property of the data. And the same three-way classification is what makes a partial second pass sensible: an implementation short of time can resolve the uncertain candidates in whatever order it likes and stop, reporting the ones it settled and the ones it did not, which is a strictly better failure mode than either extreme.

A carry is a message

There is a reading of the carry that makes its size matter beyond bookkeeping, and it is the one that connects this essay to the setting where multi-pass algorithms are actually deployed.

A pass boundary and a communication round are the same event. An algorithm that reads a stream twice on one machine, carrying cc bits between the passes, becomes an algorithm that runs on mm machines in two rounds, sending cc bits per machine in between. The carry is not an accounting device in that setting — it is the message, and the quantity that decides whether the distributed version is affordable.

That gives the three carries in the section above a second reading. A candidate set of 3,680 bits is a message a coordinator can gather from a thousand shards without noticing. An interval and a count — ninety-six bits — is nothing at all. A set of order statistics grows with the split count and is the only one of the three that would show up on a network graph.

It also explains why the carry has to be enforced rather than declared. On one machine an undeclared carry is a memory leak that flatters a number; distributed, it is a message that has to be sent and cannot be, so an algorithm whose real carry exceeds its stated one does not merely report a wrong figure — it does not run.

What is not measured here

Passes that are not identical. Everything here reads the same stream in the same order every time. An algorithm allowed to read it backwards on the second pass is strictly more powerful, and the multi-pass lower bounds in the literature are usually stated for forward passes only.

Streaming with a sorted or indexed second pass. A great deal of practical multi-pass work reads the data once to build an index and then reads selectively rather than passing over everything. That is a different resource again and none of the machinery here measures it.

The rounds-versus-passes distinction. In a distributed setting the analogous resource is a round of communication, and the two are related but not equal — one round can perform several passes in parallel over different shards. Nothing here is about that model.

Peak state against passes, for two splitting rules on two distributionsExact selection of the 0.5 quantile of 32,768 values, in p passes, with the state measured at its peak during the run. Every point is an exact answer — a run that returned anything else stops the build — so the vertical axis is the price of exactness rather than a price paid for being approximately right. The line at the top is what one pass costs: 1,048,576 bits, because an exact one-pass selector has to keep the stream, and the floor under that is a counting argument this collection performs rather than quotes. The equal-width rule needs no knowledge of the data and gets 37 times smaller as passes are added — on data spread evenly. On a heavy tail it collapses, because an equal-width cut of a range containing almost no data narrows the range and not the count; the sampled rule, which spends half its passes finding out where the data is, is barely affected. Both axes are logarithmic.10³10⁴10⁵10⁶passes over the datapeak bits of stateone pass, exact: 1,048,576 bitsradix, uniformevery point exact · 32,768 values320 bits at best
Fig. 8 The same trade with one series on it, so the shape is visible without the comparison: peak state against passes for one algorithm on one distribution, falling by a factor of thirty-six over seven points. Both axes are logarithmic and the line is nearly straight, which is the subject of the next essay.
The pigeonhole, performed: 924 prefixes through a 9-bit stateEvery 6-subset of a universe of 12 is fed to a candidate one-pass selector that keeps 9 bits, and the collision the counting argument requires is produced rather than asserted. The two prefixes shown reach the same state. They first differ at 3, which is in the first and not the second, so the first has 4 elements at or below it and the second has 3. Appending -1, -2, 12, 13, 14 — 2 sentinels below everything and 3 above — makes each stream 11 long with its median at the 4th smallest of its prefix. Those medians are 3 and 4. The candidate is in the same state and reads the same suffix, so it answers the same number and is wrong on one of them. At 10 bits — which is ⌈log₂ C(12,6)⌉ = ⌈9.85⌉ — no collision exists, so the bound is exact and not merely a bound.universe 0…11 · prefixes of 6 · candidate keeps 9 bitsthe two prefixes that collideA01234567891011B01234567891011first differencesame state — the candidate stores "7" after boththen both read the same suffix -1, -2, 12, 13, 14true median of A3true median of B4and one answer for both924 prefixes · floor ⌈log₂ C(12,6)⌉ = 10 bits10 bits collide on none
Fig. 9 And what a second pass is getting under. The pigeonhole for exact one-pass selection, performed rather than quoted: every prefix of a stated size fed through a candidate state, the collision the counting argument requires produced, and the two true answers it cannot both give.

What this makes readable

Essays that name this one as a prerequisite.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

False-positiveGuaranteeHeavy hitterHonest limitMeasurementMisra–GriesModelMulti-passState bitsStreaming modelSummaryTrade off