CMSC 641 Design & Analysis of Algorithms, Spring 2018
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
Here are the problems:
- Clearly state the induction hypothesis and what value you are
inducting on (usually some indication of the size of the problem).
- State the base case and briefly argue that it holds.
- 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.
- 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.
- Briefly describe a greedy algorithm for Exercise 16.2-4 (page
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.
- Briefly describe a greedy algorithm for Exercise 16.2-5 (page
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
The following questions ask you to provide a dynamic
programming algorithm. You must provide the following:
- 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
- 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
- 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?
- Analyze and justify the running time of your dynamic
- Planning a company party.
Problem 15-6, page 408.
Note: the dynamic programming "table" for this problem is
- 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.)
- 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:
- p(i) = the price of a new car in year i ,
for 1 ≤ i ≤ n.
- v(i, k)
= The resale value of a car purchased in year i and sold
in year k, for 1 ≤ i ≤ k ≤ n.
- m( i, k)
= the maintenance cost during year k of a car purchased in
year i, for 1 ≤ i ≤ k ≤ n.
The problem is to determine the years
. . . ,
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:
- You buy and sell cars at the beginning of the year.
- You don't have a car before year 1. (Since you have to buy a new car
in year 1, y1 = 1 .)
- You only want to purchase new cars.
- At the end of n years, you sell your last car for
v(yr , n + 1) dollars.
- Exercise 17.2-3, page 459.
- 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
operations do indeed take
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
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
≈ 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
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.
2 √10,100 < 201
- 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,
were implemented, then the amortized running time of
can be made O(1) without increasing the
amortized running time of the other operations from the first question
- Amortized weight-balanced trees.
Problem 17-3, parts a–e, pages 473–474
- Height of Fibonacci Trees.
Exercise 19.4-1, page 526.
- Off-line minimum.
Problem 21-1, parts a-c, pp. 582-583.
20 Feb 2018 10:53:17 EST
to Spring 2018 CMSC 641 Homepage