(20 points) Crabbe and Goyle following pseudocode on the board, which he claims implements target value v within an arguing a

(20 points) Crabbe and Goyle following pseudocode on the board, which he claims implements target value v within an arguing about binary search. Goyle writes the binary search for a input array A containing n elements sorted in ascending order are a bSearch (A, v) { return binarySearch(A, 1, n-1, v) } binarySearch(A, 1, r, v) { if l <= r then return -1 floor (1 + r)/2 ) m = if A [m] == y then return m if A [m]> v then return binarySearch(A, m+1, r, v) else return binarySearch(A, 1, m-1, v) (a) Help Crabbe determine whether this code performs a correct binary search. If it does, prove to Goyle that the algorithm is correct. If it does not, state the bug(s), fix the line(s) of code that are incorrect, and then prove to Goyle that your fixed algorithm is correct (b) Goyle tells Crabbe that binary search is efficient because, at worst, it divides the remaining problem size in half at each step. In response Crabbe claims that four- nary search, which would divide the remaining array A into fourths at each step, would be way more efficient asymptotically. Explain who is correct and why.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *