h109 - n 3(greedy algorithm Coin changing problem 16-1 page...

COT 6401The Analysis of AlgorithmsHomework 1Due:February 11All for solutions, provide explanation first in English followed by pseudo code. A briefcomplexity analysis, including how to derive the result, is also needed.1. (divide-and-conquer using transform-and-conquer) Compute a mode, wheremodeis avalue that occurs most often in a given list of numbers. For example, for 2, 4, 6, 2, 6,1, 6, the mode is 6. Design an algorithm with complexity Θ(nlogn).2. (divide-and-conquer and dynamic programming) Suppose your job at an investmentcompany is to buyxshares of a stock on some day and sell all these shares on some(later) day.There arei= 1,2, .., ndays.The share price at dayiisp(i).Designtwo efficient algorithms that generate the maximum profit by deciding when to buyand sell. The first solution uses divide-and-conquer with complexity Θ(nlogn). Thesecond solution applies dynamic programming to reduce the complexity to Θ(

This is the end of the preview.
Sign up
to
access the rest of the document.

Unformatted text preview: n ). 3. (greedy algorithm) Coin changing problem 16-1, page 402 in the textbook. 4. (stable marriage problem) Suppose 2 n people ( n men and n women) are either bad or good. Speciﬁcally, there are k good men and k good women. In the preference list, everyone would rather marry any good person than any bad person. Show that in a stable marriage, every good man is married to a good woman. 5. ( bonus problem ) Suppose you are given an array A with n entries with distinct values. Assume the values in the array is unimodel : For some index p between 1 and n , the values in the array entries increase up to position p and then decrease the remainder of the way until position n . Show how to ﬁnd the entry p by reading at most O (log n ) entries in A and then how to minimize the total number of readings. i...
View
Full Document