## Homework Assignments

### Homework 1, Due Thursday 02/05

1. Problem 3-3, part a, page 58. No justification is needed.
Note: omit the functions involving the lg* function.

2. Show that the following statement is true by providing the constants c and n0 in the definition of O() (big-Oh) and arguing that the definition is satisfied:
n! = O(nn)

3. Show that the following statement is true by providing the constants c1, c2 and n0 in the definition of Θ() and arguing that the definition is satisfied:
5n3 − 17 n = Θ(n3)

4. Show that the following statement is false by arguing that there cannot exist constants c and n0 that satisfy the definition of O():
3n2 − 9 n = O(n)

5. Exercise A.2-3, page 1069.

### Homework 2, Due Thursday 02/12

1. Exercise 4.3-1, parts a-c, page 75.

2. Problem 4-1, parts a-e, page 85.
Find asymptotic lower bounds only.
You must use either the recursion tree/iteration method or the substitution method. Show all work.

3. Problem 4-4, parts a, c, e & h, page 86.
Find asymptotic upper bounds only.
You must use either the recursion tree/iteration method or the substitution method. Show all work.

### Homework 3, Due Thursday 02/19

1. Exercise 6.5-7, page 142. Briefly justify the correctness and the running time of your algorithm.
Note: Be careful what you assume!

2. Exercise 6.5-8, page 142. Briefly justify the correctness and the running time of your algorithm.

3. Problem 7-3, parts a, b & c, page 161.
Note: For part a, you are supposed to argue that Stooge Sort works correctly. If we broke the array into 5 pieces, recursively sort the first three-fifths, recursively sort the last three-fifths and recursively sort the first three-fifths again, we are not guaranteed to have a sorted array at the end. (Why not?) Your argument that Stooge Sort works correctly must not be applicable to this incorrect "three-fifths" sort.

### Homework 4, Due Thursday 02/26

1. Problem 8-3, parts a & b, page 179.
Note: For this problem, you cannot just pad the numbers and strings to the same length. Your input might, for example, have n/2 − 1 strings with only 1 character and 1 string with n/2 characters. If you pad the shorter strings to length n/2, you would increase your input length to n2/4 = Ω(n2). Applying a linear-time algorithm to the modified input would take Ω(n2) time, not linear time.
Reminder: describe your algorithm at a high level. Don't use undocumented pseudocode.

2. Exercise 9.3-8, page 193.
Hint: Think recursively.

3. Exercise 9.3-9, page 193.
Additional Instruction: Prove that the location of the main pipeline that you picked does actually minimize the total length of the spurs.

### Homework 5, Due Thursday 03/05

1. Problem 8-4, page 179.

2. Exercise 9.3-6, page 192.
Note: the array you are given is not sorted.

3. Problem 15-4, page 367.

### Homework 6, Due Thursday 03/12

1. Exercise 15.3-5, page 350.

2. Problem 15-2, page 364.

3. You arrive at Waldo's World Amusement Park with T minutes before the park closes. The park has n rides and your objective is to complete as many rides as possible before the park closes. (For this problem, taking the same ride twice counts as 2 rides.) You are given a table W such that W(i,t) gives you the waiting time for ride i at time t. For convenience, assume that t is to be given as minutes before the park closes. Ride i itself takes ri minutes and all times are measured in integer minutes.

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.

Additional Instructions: For Questions 2 and 3 above, you are asked to provide a dynamic programming algorithm. You must do so by providing 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. Which entry has the solution to the original problem?
4. Analyze and justify the running time of your dynamic programming algorithm.

### Homework 7, Due Thursday 03/26

1. Greedy Trick or Treat.

Consider the following Trick-or-Treat problem. You live on a street with n houses. You have a bag to carry your Halloween candy, but your bag can carry at most K ounces of candy. You are given for each house i, an integer weight integer wi (in ounces) of the candy that the people in house i are handing out. Each house gives out one piece of candy. You can visit each house at most once. Your problem is to collect the largest number of pieces of candy from the n houses without exceeding the capacity of your bag.

Now consider the following greedy algorithm. Sort the houses according to the weight of the candy they are providing. Collect candy from the houses starting from the house that provides the lightest candy, then the next lightest, ... until your bag is full.

Give a convincing argument (i.e., a proof) that this greedy strategy results in an optimum solution to the problem given above.

2. Exercise 16.2-4, page 384.
Note: the question does ask you to prove that your algorithm produces the best solution. This is the most important part of the question.

3. Exercise 16.2-5, page 384.
Note: the question does ask you to prove that your algorithm produces the best solution. This is the most important part of the question.

### Homework 8, Due Thursday 04/02

1. Problem 16-1, parts a, c & d, page 402.

2. Exercise 22.1-6, page 530.

3. Exercise 22.2-6, page 539.

### Homework 9, Due Thursday 04/09

1. Exercise 22.3-10, page 549.

2. Exercise 22.4-3, page 552.
Note: This is for undirected graphs.

3. Exercise 22.4-5, page 552.
Note: Carefully explain your data structures. You will need to quickly find vertices with indegree zero.

### Homework 10, Due Thursday 04/16

1. Exercise 22.5-3, page 557.

2. Exercise 22.5-7. page 557.
Note: for full credit, your algorithm should run in time O(V+E).
Hint: first construct the component graph (Exercise 22.5-5). What does the component graph of a semi-connected graph look like? What about the component graph of a graph that is not semi-connected?

3. Exercise 23.2-1, page 573.

### Homework 11, Due Thursday 04/23

1. Problem 23-4, pages 577-578.

2. Exercise 24.3-6, page 600.

3. Problem 24-3, page 615.

### Homework 12, Due Thursday 04/30

1. Exercise 24.5-8, page 614.

2. Exercise 25.2-6, page 635.

3. Exercise 25.2-7, page 635.

### Homework 13, Due Thursday 05/07

1. Problem 26-1, parts a & b, page 692.
Note: For part b, assume that you are using the Edmonds-Karp algorithm for maximum flow.

2. Problem 26-4, parts a & b, page 694.
Note: Do justify the running time of your algorithm.
Additional Note: Use the Max Flow Min Cut theorem to argue that your algorithm does indeed find the maximum flow in the new flow network.

3. Network Flow: International Relief.
You are coordinating an international relief effort to clean up after a disaster. You have a list of m tasks t1, ..., tm. Task ti must be performed ki times. There are n organizations willing to help with the tasks. By prior agreement, you may ask each organization to perform 2 different tasks. However, not all organizations can perform every task. For organization j, Cj ⊆ { t1, ..., tm } is the set of tasks the organization can perform.

1. Explain how to transform the problem into a network flow problem such that the maximum flow can be used to determine whether it is possible to assign tasks to organizations such that each task ti is performed ki times. Argue that your transformation works.

2. It turns out that each organization represents one of r nationalities. In order to promote an image of international cooperation, you are asked to assign the tasks in such a way that each task is performed by organizations from more than one nation. (E.g., if "checking for gas leaks" must be performed 10 times, you should not assign all 10 to organizations that all turn out to be French. Assigning 9 to French organizations and 1 to an Italian organization would be fine.)

Explain how to transform this version of the problem into a network flow problem. You may assume that for each i,  k i ≥ 2. Argue that your transformation works.