Use python to solve this question. Don't use any libraries

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Use python to solve this question. Don't use any libraries 

Sample
>>> peak ([5,10,20,15])
20
>>> peak ([10, 20,15,2,23,90,67])
20 90
Transcribed Image Text:Sample >>> peak ([5,10,20,15]) 20 >>> peak ([10, 20,15,2,23,90,67]) 20 90
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.
Transcribed Image 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.
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY