Let's assume a list A that contains non-repeating and unsorted list of numbers. A number A[i] is called a peak if: A[i-1]SA[i]2A[i+1]. For example in the list {5,10,20,15} the peak element is 20, and...


use python


Let's assume a list A that contains non-repeating and<br>unsorted list of numbers. A number A[i] is called a<br>peak if: A[i-1]SA[i]2A[i+1].<br>For example in the list {5,10,20,15} the peak element<br>is 20, and in the list {10,20,15,2,23,90,67} the peak<br>elements are 20 and 90.<br>If the list is empty, it should print a message stating<br>

Extracted text: Let's assume a list A that contains non-repeating and unsorted list of numbers. A number A[i] is called a peak if: A[i-1]SA[i]2A[i+1]. For example in the list {5,10,20,15} the peak element is 20, and in the list {10,20,15,2,23,90,67} the peak elements are 20 and 90. If the list is empty, it should print a message stating "List is empty!" and return -1 If there's no peak element, it should print a message stating "No peak element found!" and return -1 The simplest way to find a peak element in a list is by iterating through every element and compare it with its neighbors, which will require (n) operations. You are required to find a peak by applying divide and conquer approach, which may require lesser operations. Hints: Don't sort the list. • This problem can be solved by a small variation in binary search algorithm Write a function peak () that takes a list of integers as a parameter and returns peak elements in a sorted order.
Sample<br>>>> peak ([5,10,20,15])<br>20<br>>>> peak ([10, 20,15,2,23,90,67])<br>20 90<br>

Extracted text: Sample >>> peak ([5,10,20,15]) 20 >>> peak ([10, 20,15,2,23,90,67]) 20 90

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here