Question: Below, we give an improved algorithm for peak finding. Input: Array A [ 1 . . n ] , indexes x and y , and
Below, we give an improved algorithm for peak finding.
Input: Array An indexes x and y and we are finding a peak in Axy
Return: index i x i y such that Ai is a peak
PeakFindingImprovedA x y:
mid x y
if Amid Amid
return PeakFindingImprovedA x mid
else if Amid Amid
return PeakFindingImprovedA mid y
return mid
Proof of Correctness of PeakFindingImproved algorithm
Consider Step This will be executed only if Amid Amid Therefore, any element that is a peak in Axmid will be a peak. For indexes mid it is obvious; if mid is a peak in Axmid then we know mid is a peak in Axy because Amid Amid from Step in Algorithm and Amid Amidfrom Step in Algorithm We can similarly prove for Step We can also prove Step is correct, when Step is executed.
b Write a recurrence for the running time of the algorithm
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
