For each of the following problems, use proof by induction to show that the solution produced by the greedy algorithm is the best solution. You must use proof by induction. Do not appeal to general principles (e.g., "it is always best to ...").
In your proof by induction, you must
Describe a dynamic programming algorithm that produces a schedule of rides with the maximum number of rides. (In case you thought this is a totally made up problem, check out RideMax.)
For this question, you are given the following information:
The problem is to determine the years y_{1}, y_{2}, . . . , y_{r}, when you would purchase new cars such that the total cost of car ownership from years 1 through n is minimized. The total cost is the sum of the maintenance costs for years 1 through n plus the price of each car purchased minus the resale value of each car sold.
For example, if n = 10, y_{1} = 1, y_{2} = 5, y_{3} = 7, then this solution states that you should purchase a new car in year 1, buy the second car in year 5 and buy the third car in year 7. (You would also sell the first car in year 5, the second car in year 7 and the third car at the beginning of year 11.)
In addition, you should make the following assumptions:
Additional note: the main difficulty here is splitting long inner lists. Since we have to find the middle of a long inner list when we perform a split, the split operation on a list with m items takes Θ(m) time. Furthermore, an inner list might become long not because items are added to the that list, but because items were removed from other parts of the data structure. That is, the list becomes long because 2 √n got smaller. Thus, it is possible that a single consolidate process will be required to split a non-constant number of long inner list.
For example, suppose we have a Square List with 20,000 items which has 10 inner lists that each have 201 items. Now, n = 20,000 means 2 √n ≈ 283. So, the lists with 201 items are not long. Suppose that we remove 9,900 items from the Square List (and none of the deleted items are in the 10 inner lists with 201 items). We have:
2 √10,101 > 201So, between the 9,899-th delete operation and the 9,900-th delete operation, those 10 inner lists with 201 items became long. Note that 10 ≈ (10,100)^{0.25}, so we have a non-constant number of splits to do during a single consolidate operation.
2 √10,100 < 201
Show how you can use this black box to find a 3-coloring of G in polynomial time. (I.e., you must be able to assign red, green or blue to each vertex of the graph such that no two adjacent vertices have the same color.)
Finally, note that the graph G that you give to the black box is just an undirected graph. That means you can only specify the set of vertices and the set of edges. You cannot add any additional information to the graph. For example, you cannot ask: "Can G be colored with 3 colors assuming that vertex v_{1} is red?"
Addendum: yes, you should use the "black box" many times.
In contrast, an undirected graph G = (V, E) has a Hamiltonian path from vertex s to vertex t if the path includes every vertex of G exactly once. (Here, the vertices s and t must be specified, and the path cannot be a cycle because then s = t would be visited twice.) The HAM_PATH decision problem is the following:
Construct a polynomial-time ≤_{m}-reduction from HAM_CYCLE to HAM_PATH. Make sure that you do the reduction in the correct direction. Argue that your construction is correct by proving separately both directions of the "if and only if".
N.B.: a graph can have an exponential number of cycles. So, when you show that X ∈ NP, you cannot simply guess E' and check every cycle in G. That would take exponential time.
Note: the answer to part b is "polynomial time". Describe a greedy algorithm for dividing the bag of money equally and show that it is correct. I.e., prove that when your algorithm divides the loot, Bonnie and Clyde do indeed receive equal amounts of money, then prove separately that if your algorithm does not find a way to divide the loot equally, then there is no possible way to divide the loot equally. You may find the following lemma useful for part b:
Lemma: Let a_{0}, a_{1}, a_{2}, ..., a_{k} ∈ ℕ such thata_{0} 2^{0} + a_{1} 2^{1} + a_{2} 2^{2} + · · · + a_{k} 2^{k} ≥ 2^{k+1}.Then there exist b_{0}, b_{1}, b_{2}, ..., b_{k} ∈ ℕ such that each b_{i} ≤ a_{i}, andb_{0} 2^{0} + b_{1} 2^{1} + b_{2} 2^{2} + · · · + b_{k} 2^{k} = 2^{k+1}.
The lemma says that if there is a way to combine lower denominational coins to exceed 2^{k+1} dollars, then there is a way to take a subset of those coins to total exactly 2^{k+1} dollars. This lemma is easy to prove by induction. Just break into cases where a_{k} ≥ 2, a_{k} = 1, and a_{k} = 0. You may use the lemma without proof.
Note: the restriction to paths without cycles is necessary since you can repeat a cycle arbitrarily many times. Each repetition makes the path longer. If we allowed paths from s to t with cycles, then the answer would always be "Yes, there is a path that has total weight greater than w."
Provide a simple counter-example that shows that this greedy algorithm does not produce the smallest vertex cover.
A matching M ⊆ T (not necessarily a perfect one) just requires that every x ∈ X appears in a triple in M at most once, every y ∈ Y appears in a triple in M at most once and every z ∈ Z appears in a triple in M at most once. So, a matching enforces that triples in M do not share components, but does not require that every x, y and z appears in some triple.
The optimization version of 3DM asks us to find a matching that contains the largest number of triples.
Describe a polynomial-time approximation algorithm that finds a matching that has at least 1/3 as many triples as in the maximum matching.
Argue that the approximation factor you achieve is indeed 3. Briefly state and justify the running time of your algorithm.
Note: The knapsack problem is considered NP-complete because the value of the capacity of knapsack W can be exponential in the number of items n. The dynamic programming algorithm we looked at runs in O( nW ) time, which is considered exponential time.
Devise an algorithm that gives you at least 1/4 probability of accepting the offer that pays the most. The probability is taken over the order that you open the letters which we assume has been randomized by the Post Office.
Hint: think about the second highest offer. Where can it be in the order? With what probability? How does this help you accept the highest offer?
(1,3), (2,5), (3,7), (5,11), (7,14), (8,15), (10,19)This points are not colinear (i.e., no line passes through all of the points). We wish to find a line ax + by = c such that the line minimizes the maximum absolute error, which is defined by
max_{1 ≤ i ≤ 7} | ax_{i} + by_{i} − c |where (x_{i}, y_{i}) are the coordinates of the i-th point.
Formulate a linear program (you don't have to solve it), that finds the values of a, b and c that determine the line with the smallest maximum absolute error. Place your solution in standard form.
Notes:
max x_{1} − 2 x_{3}Prove that the solution (x_{1} , x_{2}, x_{3}) = (3/2, 1/2, 0) is an optimal solution.
x_{1} − x_{2} ≤ 1
2 x_{2} − x_{3} ≤ 1
x_{1} , x_{2}, x_{3} ≥ 0