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](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f526aa5b8d5_24966f526a9bf0b1.jpg)
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
Get step-by-step solutions from verified subject matter experts
