Logarithmic Work from Repeated Halving
Repeatedly halving a positive search interval reduces its length to a constant after a logarithmic number of steps.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Write one trace
From a candidate interval of size 16, successive halvings give 8, 4, 2, and 1. Four halvings are needed because \(2^4=16\). Binary search by hand shows which sorted-order observation licenses each halving.
Count work inside a step
If each halving performs a constant amount, the halving phase takes logarithmic time. If it copies the remaining half on each step, the total copies are geometric and linear in the initial size. See slices and copies.[1]
Count integer halving until the stopping size
Repeatedly taking floor of half the current integer takes four steps from nineteen to one. Doubling nineteen to thirty-eight adds exactly one such step. By contrast a rule removing one item per step needs eighteen steps from nineteen. Draw the sizes before converting the trace to a logarithm. See recursive interval splitting.
19 → 9 → 4 → 2 → 1
38 → 19 → 9 → 4 → 2 → 1
For n≥1, floor halving to 1 takes floor(log2(n)) steps
Check whether the halving is all the work
A binary search selects one half and continues. A procedure recursively visiting both halves can make a number of calls proportional to the input size even though its depth is logarithmic. Count visited nodes separately from the longest path.