Counting Search Steps

Solution

Each comparison halves the range that could still contain the target: , then , then , and so on, so after comparisons the range has size . The search stops once the range is empty, which happens right after it reaches size , so solve , giving and . The worst case is about comparisons, against about for a linear search.

Solution

, so about 12 comparisons. Doubling the array to adds exactly one more halving, so it needs . That is one more, regardless of how large the array already was.

Solution

is under 20, while linear search’s worst case is about 500,000 comparisons, so the two are already several orders of magnitude apart. Linear search’s cost scales proportionally with , so doubling doubles the work. Binary search’s cost scales with how many times you can halve , so doubling only adds one more comparison. The gap between the two widens as grows.