Question: 1. (20 points) Suppose you are given an array A[1...n] with n entries, with each entry holding a distinct number (i.e., no two numbers of

 1. (20 points) Suppose you are given an array A[1...n] with

1. (20 points) Suppose you are given an array A[1...n] with n entries, with each entry holding a distinct number (i.e., no two numbers of A are equal). You are told that the sequence of values A[1], A[2], ..., A[n] is unimodal: For some index p between 1 and n, the values in the array entries increase up to position p in A and then decrease the remainder of the way until position n. (So if you were to draw a plot with the array position ; on the x-axis and the value of the entry A[j] on the y-axis, the plotted points would rise until x-value p, where they would achieve their maximum, and then fall from there on.) You would like to find the peak entry p without having to read the entire array in fact, by reading as few entries of A as possible. Show how to find the entry p by reading at most O(log n) entries of A. In other words, design an O(log n) time algorithm to find the peak entry p. For example, let A = {1, 4, 6, 8, 11, 12, 10, 9,7), which is be a unimodal array. The peak entry of A is 12. So the output of your algorithm may be either 12 or the index of 12 in A

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!