CMSC 641 Design & Analysis of Algorithms, Spring 2018

Homework Assignments

Homework 1, Due Tuesday 02/06

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

  1. Clearly state the induction hypothesis and what value you are inducting on (usually some indication of the size of the problem).
  2. State the base case and briefly argue that it holds.
  3. In the inductive step, argue that if a solution X for problem Π exists that is better than the greedy solution for Π, then you can construct from X a solution X′ to a smaller problem Π′ such that X′ is better than the greedy solution for Π′. (This contradicts the induction hypothesis.) Make sure that Π′ is clearly defined.
Here are the problems:

  1. Prove by induction that the greedy algorithm for the fractional knapsack problem in Section 16.2 of the textbook packs the knapsack with the greatest possible value.

  2. Briefly describe a greedy algorithm for Exercise 16.2-4 (page 384 427) and provide a proof by induction that your greedy algorithm produces an itinerary with the fewest number of stops. It would be helpful to invent some convenient notation for the locations of the gas stations where Professor Gecko can fill his water bottle.

  3. Briefly describe a greedy algorithm for Exercise 16.2-5 (page 384 428) and provide a proof by induction that your greedy algorithm produces a covering with the fewest number of unit length intervals. Here a unit length interval is just an interval [a, b] on the real line such that b = a + 1.

Homework 2, Due Tuesday 02/13

Additional instructions: The following questions ask you 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.

  1. Planning a company party.
    Problem 15-6, page 408.
    Note: the dynamic programming "table" for this problem is tree-shaped.

  2. Waldo's World.
    You arrive at Waldo's World Amusement Park with T minutes remaining until 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 expressed 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.)

  3. Car ownership.
    In this question, we consider a problem in car ownership. As a car gets older, the maintenance costs (fuel costs, repair costs, insurance costs, etc) for the car may increase to the extent that it would be advantageous to sell the current car and buy a new car. The difficulty in this problem is that the prices of new cars change from year to year, the maintenance costs of cars purchased in different years may be different and the resale value of a car can change from year to year as well.

    For this question, you are given the following information:

    The problem is to determine the years y1, y2, . . . , yr, 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, y1 = 1, y2 = 5, y3 = 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:

Homework 3, Due Tuesday 02/20

  1. Exercise 17.2-3, page 459.

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

    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 becomre 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 exmample, 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 > 201
    2 √10,100 < 201
    So, 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.

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

Homework 4, Due Tuesday 02/27

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

Homework 5, Due Tuesday 03/06

Homework 6, Due Tuesday 03/13

Homework 7, Due Tuesday 04/03

Homework 8, Due Tuesday 04/10

Homework 9, Due Tuesday 04/17

Homework 10, Due Tuesday 04/24

Homework 11, Due Tuesday 05/01

Homework 12, Due Tuesday 05/08

Last Modified: 20 Feb 2018 10:53:17 EST by Richard Chang
to Spring 2018 CMSC 641 Homepage