We have the binary search algorithm. Consider the followingvariant of the algori
ID: 3613947 • Letter: W
Question
We have the binary search algorithm. Consider the followingvariantof the algorithm, which takes as input a sorted array A[0 . . .n1] of integers and an integer
x:
Algorithm BinarySearch(A[0 . . . n 1], x):
l = 0;
r = n 1;
while l<= r
do m = (l + r)/2;
if x <=A[m]
then r = m
else l = m + 1
endif
endwhile;
if x = A[l]
then return l
else return 1
endif
Prove or disprove the following claim: If x occurs in the array A[0. . . n1], then algorithm
BinarySearch returns an index l such that A[l] = x. If x does notoccur in the array,
then algorithm BinarySearch returns 1.