subject

Alist of n distinct integers a_1, a_2, a_n is called a mountain list if the elements reading from left to right first increase and then decrease. the location of the peak is the value i where a_i is greatest. for example, the list 1, 2, 3, 7, 6 is a mountain list with a peak at 4. we also consider a list of increasing numbers to be a mountain list with a peak at n, and a list of decreasing numbers to be a mountain list with a peak at 1. give pseudocode for an algorithm based on linear search that takes as input a mountain list a_1, a_2, a_n and returns the location of the peak. show that your algorithm does no more than n - 1 comparisons on any input of size n. give an algorithm based on binary search that takes as input a mountain list a_1, a_2, a_n and returns the location of the peak. your algorithm should be able to find the peak in any list of size 16 with no more than 4 comparisons (in general, up to k comparisons for a list of size 2^k.) you should provide pseudocode and an english description of your algorithm, but you do not need to prove that it meets the requirements for the number of comparisons.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 20:00
How is the number 372 written when expanded out to place values in the base 8 (octal) number system? a. 2 x 4 + 3 x 2 + 4 x 1 b. 3 x 64 + 7 x 8 + 2 x 1 c. 3 x 8 + 7 x 7 + 2 x 6 d. 3 x 100 + 7 x 10 + 2 x 1
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
If i wanted to include a built-in calendar in a document, what option could i select? draw table insert table insert chart quick tables
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
question
Computers and Technology, 24.06.2019 06:30
Me and category do i put them in because this is science
Answers: 1
You know the right answer?
Alist of n distinct integers a_1, a_2, a_n is called a mountain list if the elements reading from l...
Questions
question
English, 18.03.2020 04:09
question
Mathematics, 18.03.2020 04:09
question
Mathematics, 18.03.2020 04:09
Questions on the website: 13722360