O(log n)

Logarithmic Time

Dream

Input doubles → only 1 more step. Incredibly efficient.

Mental model

Searching a phone book: open to the middle page, decide which half has your name, ignore the other half. Repeat. Each step eliminates 50% of what's left — so a million entries takes only ~20 steps.

Interactive Visualisation
📖  Searching a phone book: open to the middle page. Is your name before or after? Ignore the wrong half. Open to the middle of what's left. Repeat. Each step cuts the problem in half — so a million names takes only ~20 steps.
Array size:Target: 0 · max 4 steps

Steps needed (max) as n grows

83
164
325
646
1287
1k10
1M20

How it scales

n = 8

3 steps

n = 64

6 steps

n = 1,024

10 steps

n = 1,048,576

20 steps

Previous

O(1)Constant Time

Next

O(n)Linear Time