Sei sulla pagina 1di 9

COT 5405 Analysis of Algorithms, Spring 2010.

Homework 2
Due Friday, March 5 2010, 12:00pm.
Notes You may hand the homework to TAs during oce hours. You may also hand the homework to Prof. Ranka in class. No late submissions. To force you to write succinctly, we have enforced page limits. These are noted in front of each question. Answer each question on a fresh page. If the problem necessitates writing an algorithm, you must rst informally describe the algorithm, in brief, in a paragraph. You can choose to follow this up with pseudocode that formally describes the algorithm. We will peruse your pseudocode only if your English description is not clear. Write your name on the top right hand corner of your homework. Be sure to write your last name as the last word in your name. If you are designing an algorithm, you must write a formal proof of correctness. Please write legibly.

1. [1 page] (15pts) Consider a connected graph with n vertices and exactly n + 43 edges, all with distinct positive weights on them. Your task is to build a minimum spanning tree for this graph in O(n) time.

2. [ 1 page] (10pts) Consider n nite sets S1 ,, S2 ,...,Sn . You want to nd the minimum number of sets 2 from these (say some m n), such that their union (denoted by T ) is equal to the union of all n sets (denoted by R). Here is a greedy algorithm to do this: (1) Initially, T = . (2) Choose the set Sk with the largest cardinality. Then T = T Sk . (3) Among the remaining sets (i.e. those not picked so far), choose the one that contains the maximum number of elements in R T . Call this set Sp . Then T = T Sp . (4) Repeat step (3) until T = R. Example: n = 3, R = {1, 2, 3, 4, 5, 6}, S1 = {1, 2, 3, 4}, S2 = {2, 3, 5}, S3 = {5, 6}. The greedy algorithm will work as follows: (1) T = (2) T = S1 (since S1 is the largest set) (3) Now S3 is chosen, since R T = {5, 6} and S3 contains the elements 5 and 6, while S2 contains only the element 5 (and S1 was already included before). Hence, T = S1 S2 . The algorithm terminates since T = R. Find an example where the greedy strategy proposed above fails to give the best solution, i.e. minimum number of sets to form T .

3. [1 page] (15pts) Consider a variant of the minimum spanning tree (MST) problem. This variant asks you to compute a spanning tree T such that the maximum weight of any edge in T is minimized. Let us call this type of a spanning tree as the least-max-edge spanning tree (LMEST). Is it true that every LMEST is also an MST? Is it true that every MST must be an LMEST? Provide full justication for both answers.

4. [1 page] (15pts) Consider a seminar hall in which several lectures are to be held on a particular day. The lectures are labeled as L1 , L2 , ..., Ln with start times s(L1 ), s(L2 ), ..., s(Ln ) and nish times f (L1 ), f (L2 ), ..., f (Ln ). Unfortunately, some of these start and nish times overlap, and at any given time instant, one and only one lecture can be held in the hall. Lectures Li and Lj are said to be non-conicting if and only if their start and end times do not overlap. To develop an ecient greedy algorithm that takes the start and nish times as input and outputs a non-conicting schedule of maximum possible number of lectures, consider the foll. greedy strategies. Which of these is optimal? Prove or disprove (a counterexample suces for disproving): (1) Pick the lecture with the earliest nishing time and add it to the list of chosen lectures. Discard all lectures that conict with it. Continue this way till all non-conicting lectures have been considered. Output the list of chosen lectures. (2) Pick the lecture with the smallest duration and add it to the list of chosen lectures. Discard all lectures that conict with it. Continue this way till all non-conicting lectures have been considered. Output the list of chosen lectures.

5. [ 1 page] (10pts)Given a set of points on the real line {x1 , x2 ,..., xm } , determines the smallest set of 2 unit-length closed intervals that contains all of the given points. Argue that your algorithm is correct.

6. [1 page](15pts) Consider a set of positive integers {1 , 2 , ..., n } arranged in strictly increasing order where 1 = 1 and let Y be another positive integer. You have been asked to come up with non-negative n n integers {1 , 2 , ..., n } such that j=1 j is minimized under the constraint that j=1 j j = Y . (In other words, you want to nd non-negative values such that their sum is as small as possible, but for whatever values you choose, the constraint must be satised. Note that some of the values could be zero). Here is a greedy strategy for solving this problem: (1) j = n (2) while Y > 0 START WHILE (2.1) Find the greatest integer multiple of j such that j Y . (2.2) Set j = and Y = Y j . (2.3) Set j = j 1 END WHILE (1)Prove that this strategy is not optimal in the general case by coming up with a counterexample. (2)Suppose that j are powers of c, i.e., j is cj1 for some integers c > 1. Show that in this condition the greedy algorithm always yields an optimal solution.

7. [ 1 page] (10pts) Assume one of your friends is driving a motorcycle from Gainesville to Los Vegas 2 along I-12. The bikes gas tank, when full, has enough gas to travel k miles, and a map gives distances between dierent gas stations on the route. Your friend wishes to make as few gas stops as possible along the way. Give an ecient method by which you can determine at which gas stations your friend should stop. Prove that your strategy yields an optimal solution.

8. [ 1 page] (10pts) You are the manager in a rm where the length of working time and the start time 2 of work is dierent for dierent employees. For example, person X works everyday from 8 to 11 AM, person Y from 9 AM to 1 PM, person Z from 2 to 10 PM etc. You task is to create a workforce consisting of maximum number of people possible with non-overlapping work hours (if a person leaves at 7 AM and another starts at 7 AM, that is not an overlap). You use the following (Greedy) strategy: (a) Choose the person (say X) with least number of working hour over- laps with other workers. (b) Eliminate all people having working hour overlaps with X. (c) Choose the next person with the least number of overlaps with the remaining people, and so on. Does this strategy yield the set of maximum people? If yes, prove it. Otherwise, just give a counterexample.