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