BINARY SEARCH
i := 1
j := n
while (i<j) do
m := [ (i+j)/2 ]
if (x > am) then
i := m+1
else
j := m
if (x ≠ ai) then
i := 0
return i
Let n = 2k + r, 0 ≤ r < 2k (r < n/2)
We always do k iterations;
we sometimes (2r/n of the time) do an extra one.
A = k + 2r/n, where k = [lg n]
CASE 2: x is not in the list (n+1 intervals equally likely)
Each interval goes with the succeeding list member.
(The last interval goes with the last list member.)
The last list member never requires an extra iteration.
A = k + 2r/(n+1), where k = [lg n]