Question PSC-ARR-0045
MediumWhat is the output of this pseudocode?
Integer a[7] = {1, 3, 5, 7, 9, 11, 13}
Integer lo = 0, hi = 6, mid, steps = 0
while (lo <= hi)
mid = (lo + hi) / 2
steps = steps + 1
if (a[mid] == 11)
break
else if (a[mid] < 11)
lo = mid + 1
else
hi = mid - 1
end if
end while
Print mid, steps
- A.
5 3
- B.
6 3
- C.
Sign up free to see the answer and a step-by-step explanation.