Computers and Technology

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.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, melissalopez12
Write a function so that the main program below can be replaced by the simpler code that calls function original main program: miles_per_hour = float( minutes_traveled = float( hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('miles: %f' % miles_traveled) sample output with inputs: 70.0 100.0 miles: 116.666667
Answers: 3
image
Computers and Technology, 23.06.2019 01:30, winstonbendariovvygn
1. which of the following is a search engine? a) mozilla firefox b)internet explorer c)google d)safari 2. which of the following statements is true? a) all search engines will provide the same results when you enter the same query. b) all search engines use the same amount of advertisements. c) some search engines are also browsers. d) search engines often provide different results, even when you enter the same query.
Answers: 2
image
Computers and Technology, 23.06.2019 06:30, arguellesjavier15
Who can provide you with a new password when you have forgotten your old one? your provide you with a new password in case you forget your old one.
Answers: 3
image
Computers and Technology, 23.06.2019 07:30, devnnn44
What is the original authority for copyright laws
Answers: 1
Do you know the correct answer?
Alist of n distinct integers a_1, a_2, a_n is called a mountain list if the elements reading from l...

Questions in other subjects:

Konu
Mathematics, 18.04.2021 04:20
Konu
Mathematics, 18.04.2021 04:20
Konu
History, 18.04.2021 04:20