Question: Suppose you are given an array A with n entries, with each entry holding a distinct number. You are told that the sequence of values

Suppose you are given an array A with n entries, with each entry holding a distinct number. 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. For example, the array A =
[1345678521] is unimodal, with the entries increasing up to position A[7]=8 and decreasing afterwards. Implement an algorithm that finds the peak entry p without having to read the entire array. Your algorithm should run in O(logn). After designing the algorithm, prove that the running time of the algorithm is O(logn).
** Include the following: 1) a listing of your algorithm (pseudo code),2) prove that the running time of the algorithm is O(logn),3) Source code (C++).

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!