Question: procedure binary search ( x : integer, a 1 , a 2 , dots, a n : increasing integers ) i : = 1

procedure binary search (x : integer, a1,a2,dots,an : increasing integers)
i:=1\brace i is left endpoint of search interval \rbrace
j:=n\brace j is right endpoint of search interval \rbrace
while m:=|??i+j2??|x>ami:=m+1j:=mx=ai=ixx1256781011x=,n=,a2=,a4=i=,j=,m=i
begin
m:=|??i+j2??|
ifx>am then i:=m+1
else j:=m
end
ifx=ai then location : =i
else location :=0
Vbrace location is the subscript of term equal tox,or0ifxis not found ?rbrace
Suppose our list of increasing integers is shown in the table below
1256781011
Suppose we conduct the binary search algorithm on this list where we search for 10.
(a)In the language of the algorithm above, enter the correct values for the following variables for this particular search:
x=,n=,a2=,a4=
(b) After the first iteration of the while loop, what are the values of the following variables?
i=,j=,m=
procedure binary search ( x : integer, a 1 , a 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!