Question: ALCORITHM3 The Binary Search Algorithm. procedure binary search (x: integer, al.a2. . a. increasing integers) = 1[i is left endpoint of search interval} = n

 ALCORITHM3 The Binary Search Algorithm. procedure binary search (x: integer, al.a2.

ALCORITHM3 The Binary Search Algorithm. procedure binary search (x: integer, al.a2. . a. increasing integers) = 1[i is left endpoint of search interval} = n U is right endpoint of search interval) while i am then i := m + 1 else j := m lfx_a;then location := i else lo ation : 0 return locationllocation is the subscript i of the term equal to x, or 0 ifx is not found) 26. Change Algorithm 3 so that the binary search procedure compares x to a at each stage of the algorithm, with the algorithm terminating if x = a", what advantage does this version of the algorithm have? 2. (20 points) Exercise 26, p. 203. Provide pseudocode and complexity for this algorithm C&ange Algorithm 3, p. 195, so that the binary search procedure compares z t9m at each stage of the algorithm, with the algorithm terminating if (a) Write what an advantage has this version of the algorithm (b) Write a formula for a function which expresses the number of comparisons for the eements of a sorted sequence a,....an against the target z in the worst and the best cases (e) Classify the algorithm in the worst case using the big-O asymptotic notation

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!