Question
Let A[1 . . . n] be an array of n distinct integers. We say that A is peaked, if there exists an index 1
Let A[1 . . . n] be an array of n distinct integers. We say that A is peaked, if there exists an index 1 k n such that: (1) For all 1 i < k, A[i] < A[i + 1] and (2) for all k < i n, A[i 1] > A[i]. That is, the array increases until k and decreases afterward. Call the index k the peak of A. Describe an algorithm which in O(log n) time finds the peak of a given peaked array A[1 . . . n] consisting of n distinct integers. Specifically, give short descriptions of how your algorithm works, why it is correct, and why it achieves the stated running time
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started