binary_search(k)
top <- 1
bot <- number of records in file
loop
mid <- floor [(top + bot) / 2]
get record(mid)
if key(mid) = key(k) then
FOUND
else if key(mid) > key(k) then
bot <- mid
else
top <- mid
if top > bot then
FAIL
exit when FOUND or FAIL
end loop
Correct the algorithm and explain why it might not work otherwise.