


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Dynamic Programming
American coins come in five different values, namely 50-cent, 25-cent, 10- cent, 5-cent, and 1-cent coins. Therefore, if we wanted change for 11 cents (or 11¢), we can do this with one 10¢ coin and one 1¢ coin, or two 5¢ coins and one 1¢, or one 5¢ and 6 1¢ coins, or with eleven 1¢ coins. So there are four ways to give change for 11¢. How many ways are there to make change for N ¢? (And how can you compute this number efficiently?)
The current class of students at Sandhurst has an annual picnic (ok, maybe they don’t really do this, but for the purposes of this question they do...). This year it happens that the picnic has fallen on a rainy day and the ranking officer decides to postpone the picnic and must notify everyone by phone. Here is the mechanism for doing this. Each person except for the ranking officer reports to a unique superior officer. Thus, the reporting hierarchy can be described as a tree T , rooted at the ranking officer, in which each other node v has a parent node u equal to his or her superior officer. Conversely, we can call v a direct subordinate of u. See the picture below, where A is the ranking officer, B and D are direct subordinates of A, and C is a direct subordinate of B.
m
m m
m
To notify everyone of the postponement, the ranking officer first calls each of her direct subordinates, one at a time. As soon as each subordinate gets the phone call, he or she must notify each of his or her direct subordinates, one at a time. The process continues in this was until everyone is notified. Note that each person in this process will only call direct subordinates, for example A would not be allowed to call C. We can picture this notification process as divided into rounds. In one round, each person who has already learned of the postponement can call one of his or her subordinates on the phone. The number of rounds it takes for everyone to be notified might depend upon the sequence in which each person calls their direct subordinates. In the given example, it will take only two rounds if A starts by calling B, but will take three rounds if A starts by calling D. Give an efficient algorithm that determines the minimum number of rounds needed for everyone to be notified for a rooted tree T as described above. How can you output a sequence of phone calls (i.e. a schedule for each person) that achieves this minimum number of rounds?
j sj fj vj 1 0 6 2 2 2 10 4 3 9 15 6 4 7 18 7
Solve this instance of the weighted interval scheduling problem, i.e. find a set of (non-conflicting) intervals with maximum total weight.
(Note: For such a small set of intervals, it’s likely “easy” to see the solution without much work, but the intention is for you to understand how the algorithm we discussed in class works. So I would really expect you to find the p(j) values we defined, and the values Opt(j) that would be computed to find the solution.)
the subsequence consisting of 4, 5 , 10 is an increasing subsequence, as is − 3 , 0 , 3 , 5 , 10. Your task is to find a longest subsequence so that the values are strictly increasing. (There might be repeated numbers in the original sequence, but there can be no repeats in a longest subsequence since it must be strictly increasing.) Hint: Define L(j) to be the length of the longest increasing subsequence that ends at (and includes) position j. How can you find L(j) in terms of the values L(i) for i < j? Once you know the L(j) values, what’s the answer to the original problem? And how long does it take to compute all of the L(j) values?