Question: Problem 2 . Divide and Conquer 1 . Complete the multiple choice questions on Gradescope ( the assignment called Homework 7 ( recurrences )
Problem Divide and Conquer
Complete the multiple choice questions on Gradescope the assignment called "Homework recurrences
Suppose there is a line of n cells. The neighbors of a cell are the cells directly to the left and right if they exist
Each cell i contains a value Ai and no two cells have the same value. We say a cell is a peak if it has a larger value than both of its neighbors or its one neighbor, if it is at one of the two ends
Your goal is to find an algorithm that takes as input an array A of values and returns the location of a peak. For example, on input A your algorithm could return or indexing from since all those locations are peaks.
Note that at least one peak must exist in the array, since no two cells have the same value.
a You first consider a greedy approach: starting at a random cell, you check if it is a peak. If it is you are done, If not, move to the neighboring cell with the higher value and repeat. Show that this greedy approach reads Omegan cells in the worst case that is give a type of input where it must read a large part of the array
b Write an algorithm that solves this problem and reads at most Olog n cell values in the worst case.
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
