[SOLVED] Algo Homework 02-Peak Finding Problem

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon HW02-x0ex9l.zip (189 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (2 votes)

Given an array of integers. Find a peak element in it. An array element is peak if it is NOT smaller than its neighbors. For example, for input array {5, 10, 20, 15}, 20 is the only peak element.

For corner elements, we need to consider only one neighbor. Following corner cases give better idea about the problem.

1) If input array is sorted in strictly increasing order, the last element is always a peak element. For example, 50 is peak element in {10, 20, 30, 40, 50}. 2) If input array is sorted in strictly decreasing order, the first element is always a peak element. 100 is the peak element in {100, 80, 60, 50, 20}.

3) If all elements of input array are same, every element is a peak element.

Sample input

5,10,20,15

100,80,60,50,20

10,20,30,40,50

Sample output

Find it! The peak element is 20

Find it! The peak element is 100 Find it! The peak element is 50

Β 

  • HW02-x0ex9l.zip