Question: rocedure function ( x: integer, a 1 , a 2 , . . . , an: increasing integers ) i : = 1 { i

rocedure function (x: integer, a1, a2,..., an: increasing integers)
i :=1{i is left endpoint of search interval}
j := n {j is right endpoint of search interval}
while i < j
m :=|_(i + j)/2_|
if x > am then i := m +1
else j := m
if x = ai then location := i
else location :=0
return location{location is the subscript i of the term ai equal to x, or 0 if x is not found}
What is the worst-case scenario time complexity of this algorithm?
Group of answer choices
O(1)
O(n2)
O(n)
O(logn)

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 Databases Questions!