LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

Checking one customer record takes 10 µs. With a million customers, why can a logarithmic search answer in about 200 µs when a linear scan needs 10 seconds?

A linear scan may have to check all $10^6$ entries; a logarithmic search halves the candidates at each step, and $\log_2 10^6 \approx 20$ — so 20 steps instead of a million, about 50,000 times faster.

Linear, worst case: the customer could be the last entry, so you plan for $10^6 \times 10\,\mu s = 10$ s. Starting from the back or guessing the likely half does not change the worst case.

Logarithmic: with the right combination of data structure and algorithm (a sorted array with binary search, or a balanced search tree), each step throws away half of what is left. After $k$ steps, $10^6 / 2^k$ candidates remain, which reaches 1 at $k \approx 20$. So $20 \times 10\,\mu s = 200\,\mu s$, and $10\,s / 200\,\mu s = 50{,}000$.

The estimate is fast to make once you know the powers of two by heart. Here, as almost everywhere in algorithm analysis, $\log$ means $\log_2$:

Power Value Read as
$2^{10}$ 1,024 ≈ 1 thousand (Kilo)
$2^{20}$ 1,048,576 ≈ 1 million (Mega), about 5 % over
$2^{30}$ ≈ $1.07 \times 10^9$ ≈ 1 billion (Giga)
$2^{32}$ ≈ $4.3 \times 10^9$ 4 Gi: what 32 bits can address

So $\log_2$ of a thousand is about 10, of a million about 20, of a billion about 30. Multiplying the data by a thousand adds only ten steps. The 5 % gap between $2^{20}$ and $10^6$ is irrelevant for this kind of estimate.

Go deeper:

  • doc Binary search — the halving argument and why it needs sorted, randomly accessible data.

From Quiz: ADS / Asymptotic Analysis, O-Notation and Recursion | Updated: Dec 01, 2026