Question: Consider the following search algorithm: procedure binary search (x, L= a1,,an; a1an) i := 1 j := n while ( ij) m := if x

Consider the following search algorithm:

procedure binary search(x, L=Consider the following search algorithm: procedure binary search(x, L=a1,,an; a1an) i :=a1,,an; 1 j := n while (ij) m := if x = ama1an) i := 1 j := n while (then return m else if x then j := m - 1ij) m := else i := m + 1 end while return -1 Prove that if x = am then return m else if x then j := m - 1 else i := m + 1 end while return -1

Prove that the algorithm correctly returns a value k where x = ak or it returns -1 if there is no such k.

di

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!