SECTION 05 / 17

How much work does binning save?

1 min read
On this page 1 headings
Nine objects need 36 all-pairs checks. Three bins of three need only 3 + 3 + 3 = 9 within-bin checks.
Nine objects need 36 all-pairs checks. Three bins of three need only 3 + 3 + 3 = 9 within-bin checks.

For a bin containing nᵢ items, the pair count is nᵢ(nᵢ−1)/2. Add that number over all bins. This works even when the bins are not the same size.

Within-bin pair checks=∑i=1kni(ni−1)2\text{Within-bin pair checks}=\sum_{i=1}^{k}\frac{n_i(n_i-1)}{2}

If k bins have exactly equal sizes n/k, the sum simplifies to n(n/k−1)/2. Compared with n(n−1)/2, the exact reduction factor is (n−1)/(n/k−1), provided the denominator is nonzero. This is about k for large bins. Equal-size formulas require equal counts, not merely equal-width ranges.

REAL COURSE DATA · THINK BEFORE EACH STEP

Explore the cost of binning

Trace the records, compare the methods and watch what changes. Back and Reset let you try again.

Ready

CURRENT RECORD X

Ready to begin

Choose Next step to follow the actual course records.

What we remember

Processed
0

Start with Next step. Predict what changes before reading the explanation.

Well-chosen bins can save time. One crowded bin saves no pair checks, and extra bins need extra space.
Well-chosen bins can save time. One crowded bin saves no pair checks, and extra bins need extra space.

Three checks before you use bins

First, prove that excluded cross-bin pairs cannot matter for an exact search. Second, inspect the actual bin sizes: uneven distribution changes the saving. Third, include the cost of grouping and storage. Physical bins take desk space; computer bins take memory. Memory is large but not unlimited.

If every bin has at most one card, there are zero within-bin pair checks. Do not divide by zero to call the speedup a finite factor. You still had to read and place the cards. Creating thousands of empty bins may also waste space; using only bins that occur can be helpful.

Try it yourself

Nine cards split into bins of 7, 1 and 1. How many pair checks remain?

Show explained answer

7 × 6 ÷ 2 + 0 + 0 = 21. This is more than the 9 checks for three balanced bins of 3.

Try it yourself

Does doubling the number of bins always halve the whole running time?

Show explained answer

No. Some bins may be empty or crowded. Grouping, lookup and storage cost work too. The equal-size pair formula describes only a particular comparison pattern.

Try it yourself

What does the time–space trade-off mean here?

Show explained answer

Using more labelled groups can avoid repeated comparisons, but the groups require more storage or desk space.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑