Question: Problem 2 . Divide and Conquer 1 . Complete the multiple choice questions on Gradescope ( the assignment called Homework 7 ( recurrences )

Problem 2. Divide and Conquer
1. Complete the multiple choice questions on Gradescope (the assignment called "Homework 7(recurrences)")
2. 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 \( A[i]\), 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=[5,4,3,6,2,7,0,-1,-2]\), your algorithm could return 0,3 or 5(indexing from 0), 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 \(\Omega(n)\) 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)\( O(\log n)\) cell values in the worst case.
Problem 2 . Divide and Conquer 1 . Complete the

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 Programming Questions!