=========================================================================== CSC 373 Homework Assignment 1 Fall 2008 =========================================================================== Due: by 6pm on Tue 30 Sep Worth: 8% For each question, please write up detailed answers carefully: make sure that you use notation and terminology correctly, and that you explain and justify what you are doing. Marks *will* be deducted for incorrect or ambiguous use of notation and terminology, and for making incorrect, unjustified, ambiguous, or vague claims in your solutions. 1. Prof. Pushover has agreed to assign as much of his TAs' time as necessary to ensure that his course bulletin board is monitored around the clock (24 hours a day, 7 days a week) throughout the term. Suppose that his TAs have given him their weekly availabilities, specified as intervals [s_i,f_i] where s_i < f_i are the start and end times of each available time slot, over some suitable range of non-negative integers. Prof. Pushover would like to draw up a monitoring schedule with the following properties: I- at every point in time, there is at least one TA available to monitor the course bulletin board, i.e., there are no gaps in the schedule, although it's OK if there is overlap, and II- the TAs are not overworked, i.e., the schedule uses as few available time slots as possible to achieve property I, so that there are enough TA hours left over to help out with marking. Note that this problem is a "dual" to the activity scheduling problem. With the same kind of input -- intervals [s_1,f_1], ..., [s_n,f_n] -- we are asked a complementary question -- to find a subset of intervals that totally cover the range from the earliest start time to the latest finish time, with overlap allowed, using as few intervals as possible. (a) Give an ordering of the intervals for which the natural greedy algorithm does not always find an optimal solution -- include a description of some specific input for your algorithm, show the solution found by the greedy algorithm, and justify that it is not optimal. (b) Design a greedy algorithm that solves this problem, i.e., on input [s_1,f_1], ..., [s_n,f_n], your algorithm either produces a valid schedule that uses the smallest number of intervals, or it correctly states that no such schedule is possible. Analyze the running time of your algorithm, and *prove* its correctness. 2. Consider the coin-changing problem from Exercise 1. As you've seen, the natural greedy algorithm works for certain denominations but not for others. We would like to see if we can find general properties of denominations that would guarantee that the greedy algorithm always works, without having to do a full proof of correctness. (a) Suppose each denomination is an integer multiple of the previous denomination, i.e., -] k_1, k_2, ..., k_{n-1} (- N such that d_1 = 1 < d_2 = k_1 d_1 < d_3 = k_2 d_2 < ... < d_n = k_{n-1} d_{n-1}. Prove or disprove: the natural greedy algorithm yields an optimal solution for all such denominations. (b) Suppose each denomination is at least twice as large as the previous one, i.e., d_{i+1} >= 2 d_i for i = 1,2,....,n-1. Prove or disprove: the natural greedy algorithm yields an optimal solution for all such denominations. (c) BONUS! Warning: this is difficult, and it will be marked harshly -- credit will be given only for making significant progress toward a correct answer. Can you find a more general condition that guarantees that the natural greedy algorithm will yield an optimal solution for all denominations that satisfy your condition? Can you prove that this is the case? Can you prove that the natural greedy algorithm will fail for all denominations that do not satisfy your condition? 3. For any undirected, connected, weighted graph G *with non-negative integer weights*, let m(G) represent the total weight of a minimum spanning tree of G. (a) Suppose that we pick one edge in G whose weight is positive, and reduce the weight of that edge to zero. Show that this does not necessarily reduce m(G), i.e., give a specific weighted graph G and an edge e in G with w(e) > 0, such that setting w(e) = 0 does not change m(G). (b) Suppose that we pick one edge in G whose weight is *maximum*, and reduce the weight of that edge to zero. Does this guarantee a reduction in m(G)? If so, give a short proof that m(G) always decreases; if not, give a counter-example (as in part (a)). (c) Give an efficient algorithm that takes as input an undirected, connected, weighted graph G together with one of its minimum spanning trees T, and that outputs one edge e of G with the property that reducing the weight of e to zero yields the maximum reduction possible to m(G). Analyze the running time of your algorithm (for full marks, it should run in linear time), and prove that it is correct. 4. A "ladder" is a very restricted type of graph with vertex set V = {a_1, a_2, ..., a_n, b_1, b_2, ..., b_n} and edge set E = {(a_i,b_i) : 1 <= i <= n} u {(a_i,a_{i+1}), (b_i,b_{i+1}) : 1 <= i <= n-1}. Pictorially, a ladder looks like this: a_1 --- a_2 --- a_3 -- ... -- a_{n-1} --- a_n | | | | | | | | | | b_1 --- b_2 --- b_3 -- ... -- b_{n-1} --- b_n Suppose that each *vertex* v in a ladder has a positive integer weight w(v). We wish to find an independent set in this ladder (a subset of vertices with no edge between any two of them) such that the total weight of the vertices in the independent set is maximal. (a) Give a natural greedy algorithm for this problem. Prove that your greedy algorithm always yields an optimal solution, or give a specific counter-example to show that your greedy algorithm does not always work (include the output produced by your algorithm and justify that it is not optimal). (b) Give a dynamic programming algorithm that solves this problem. Justify that your algorithm is correct (give an argument about the recursive structure of optimal solutions), and analyze the worst-case running time of your algorithm. /Hint/: You will need to store values in more than one array, where the values in one array depend on the values in other arrays.