# Homework Assignments

### Homework 1, Due Thursday 02/05

Note: When you describe an algorithm, do not use code or pseudocode. Write in clear English paragraphs that describe the high-level strategy of your algorithm. For example, if you want to sort an array, just write "sort the array A". Pictures are often very helpful. If the logic is quite detailed, you may use pseudocode, but this is in addition to your English explanation not instead of it.

1. Coin Changing. Problem 16-1, parts a – c, pp. 446–447.

Further Instructions: When you argue that a coin changing algorithm is optimal, you must prove that your algorithm uses no more coins than any other way to make change for n cents using the specified denominations. Your proof must hold for all n. You must not appeal to general principles (e.g., "It is always better to.."). As a guideline, your proof must not work for your answer to part c.

2. Scheduling to minimize average completion time. Problem 16-2, part a, page 447.

Further Instructions: You must prove that the schedule produced by your algorithm has an average completion time that is lower than or equal to the average completion time of any other schedule. Appeals to general principle (e.g. "It is always better to ...") are not acceptable proofs because they simply restate what needs to be proven.

3. Signing free-agent baseball players. Problem 15-12, page 411–412.

Additional instructions: When you are asked to provide a dynamic programming algorithm. You must provide the following:

1. Define a function OPT that can be used to solve this dynamic programming problem. To do this, you must describe the input parameters to OPT and the "return value" using English sentences. (Note: you are specifying the input-output relation of the function. You should not describe how to compute the function.)
2. Give a mathematical formula that shows how OPT can be computed recursively. Then, explain all the major parts of the formula using English sentences. Remember to include the base cases.
3. Describe how OPT can be computed bottom up using a dynamic programming table. Be sure to include a description of the dimensions of the table and the order that the entries of the table are to be filled. Draw a diagram. Which entry has the solution to the original problem?
4. Analyze and justify the running time of your dynamic programming algorithm.

### Homework 2, Due Thursday 02/12

1. Bitonic Euclidean Traveling Salesman Problem. Problem 15-3, page 405.

Hint: Let p1 be the leftmost point (i.e., the point with the smallest x-coordinate) and let p2 be the second leftmost point (i.e., the point with the second smallest x-coordinate). Argue that the line between p1 and p2 will always be part of any bitonic traveling salesman tour. How does this help you define the recursive subproblems?

Additional Instructions: When you are asked to provide a dynamic programming algorithm. You must provide the following:

1. Define a function OPT that can be used to solve this dynamic programming problem. To do this, you must describe the input parameters to OPT and the "return value" using English sentences. (Note: you are specifying the input-output relation of the function. You should not describe how to compute the function.)
2. Give a mathematical formula that shows how OPT can be computed recursively. Then, explain all the major parts of the formula using English sentences. Remember to include the base cases.
3. Describe how OPT can be computed bottom up using a dynamic programming table. Be sure to include a description of the dimensions of the table and the order that the entries of the table are to be filled. Draw a diagram. Which entry has the solution to the original problem?
4. Analyze and justify the running time of your dynamic programming algorithm.

2. Inventory Planning. Problem 15-11, page 411. Follow the additional instructions given above.

3. Exercise 17.2-3, page 459.

### Homework 3, Due Thursday 02/19

1. Square Lists.
Read the description of the Square Lists data structure from Project 1 of CMSC341 Data Structures (Fall 2013).
Use the accounting method to show that the addFirst(), addLast(), removeFirst(), add(), remove(), get() and set() operations do indeed take O(√n) amortized running time as claimed in the write up.
2. Square Lists + addendum.
Scroll down to the addendum at the end of the project description for Square Lists.
Use the accounting method to show that if the additional strategies ( early emptylist deletion, don't make long lists, early splits, early merge, delayed consolidation, and delayed splits ) were implemented, then the amortized running time of addFirst() removeFirst() and addLast() can be made O(1) without increasing the amortized running time of the other operations from the first question beyond O(√n).
3. Exercise 21.3-5, page 572.
Additional Instructions: Use the accounting method for your amortized analysis.

### Homework 4, Due Thursday 02/26

1. Amortized weight-balanced trees. Problem 17-3, parts a–e, pages 473–474
2. Off-line minimum. Problem 21-1, parts a-c, pp. 582-583.
3. Height of Fibonacci Trees. Exercise 19.4-1, page 526.

### Homework 5, Due Thursday 03/05

1. Problem 19-3, part a, page 529.
2. Exercise 26.2-10, page 731.
3. Exercise 26.2-12, page 731.

### Homework 6, Due Thursday 03/12 03/26

1. Max Flow by Scaling. Problem 26-5, parts a–f, pages 762–763.

2. Spring 2010, Quiz 3. Do Quiz 3 from Spring 2010: CMSC641-Spring-2010-Quiz3.pdf.

3. Fall 2104, Test 4. Do Test 4 from Fall 2014: CMSC641-Fall-2014-Test4.pdf.

### Homework 7, Due Thursday 04/02

1. 3-coloring a graph. Suppose you are given a "black box" that can decide the 3-Coloring problem in constant time. That is, when you give the black box an undirected graph G, it will either say "Yes, G can be colored with 3 colors" or "No, G cannot be colored with 3 colors."

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.)

2. Hamiltonian Path. 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. The HAM_PATH decision problem is the following:
Input: an undirected graph G = (V, E) and two designated vertices sV and tV.
Decide: Does G have a Hamiltonian path from s to t?

Construct a polynomial-time ≤m-reduction from the Hamiltonian Cycle problem to HAM_PATH.

3. An edge in every cycle. Consider the following decision problem X:
Input: a directed graph G = (V, E) and a number k.
Decide: Does there exist a subset of edges E'E such that |E'| ≤ k and for every cycle in G, at least one edge in the cycle is in E' ?
Show that X is NP-complete.

Note: 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.

### Homework 8, Due Thursday 04/09

1. Exercise 34.5-7, page 1101.

2. Problem 34-2, parts a-d, page 1102.

3. Test 5 from last semester CMSC641-Fall-2014-Test5.pdf

### Homework 9, Due Thursday 04/16

1. Exercise 35.2-5, page 1117.

2. Problem 35-1, parts b - e, page 1134.

3. Problem 35-2, parts a & b, pages 1134-1135.

### Homework 10, Due Thursday 04/23

1. Exercise 35.1-4, page 1111. Argue that the solution given by your algorithm is indeed the smallest vertex cover.

2. Exercise 35.5-4, page 1134. Justify your answer.

3. Three-dimensional matching, revisited. Recall that in the three-dimensional matching problem (3DM) we are given three sets X, Y and Z such that the sizes of the three sets are the same. That is, for some m, m = | X | = | Y | = | Z |. We are also given a set of triples TX × Y × Z. The NP-complete problem we discussed in class asks if there exists a perfect matching — that is, a subset of triples T'T such that | T' | = m and every xX appears in a triple in T' exactly once, every yY appears in a triple in T' exactly once and every zZ appears in a triple in T' exactly once.

A matching MT (not necessarily a perfect one) just requires that every xX appears in a triple in M at most once, every yY appears in a triple in M at most once and every zZ 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.

### Homework 11, Due Thursday 04/30

1. You toss n balls into n bins. For each toss there is a 1/n probability that the ball you toss lands in any one of the bins. After n tosses, what is the expected number of empty bins?
2. You keep tossing balls into bins until one of the bins has a two balls. Again, for each toss there is a 1/n probability that the ball you toss lands in any one of the bins. What is the expected number of tosses?
3. Mission Impossible? You are a super-secret mercenary spy. You have just completed your most recent job and you are entertaining offers for the next job. Unlike the good guys on TV, you just want to pick the job that pays you the most. (Hence "mercenary".) You have n offers from various nefarious organizations. These offers arrived in your mailbox (the physical one) in random order while you were away. Unfortunately, the offers self-destruct in 5 seconds as soon as you open the letter. Basically you have decide right away to accept the mission or move on to the next offer. Once you accept a mission, you are committed and cannot accept offers from the letters you have not yet opened.

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?

### Homework 12, Due Thursday 05/07 Tuesday 05/12

1. 0-1 Integer Programming. Exercise 34.5-2, pages 1100-1101.

2. Linear Program for shortest paths. Exercise 29.2-2, page 863.

3. Maximum bipartite matching. Exercise 29.2-6, page 864.
(Note: for this problem, do not worry about the linear program producing fractional solutions. It turns out that bipartite matching is "special" and this won't happen.)

Last Modified: 6 May 2015 08:02:48 EDT by Richard Chang
to Spring 2015 CMSC 641 Homepage