Analysis of Algorithms 91.503 (section 201)
Spring, 2005
Homework #1
Assigned: Tuesday, 1/25
Due: Tuesday, 2/1
start of lecture
This assignment covers textbook material in Chapter 15 (Dynamic Programming)
plus review material from 91.404 (undergraduate algorithms).
1. (10 points) Function Order of Growth:
Given the following 4 functions:
4 3 lg n
 n4 
nlg 2  
 8 
nlg lg 3 n
n lg n2
List the 4 functions in order of nondecreasing asymptotic size.
Justify your answer.
2. (10 points) Algorithm & Problem Bounds: Let P be a problem. Suppose that the
worst-case asymptotic running time complexity of P is in ( n2 lg(n3lgn) ) and is
also in O( n3 lgn ). That is, we know that there exists an algorithm solving P whose
worst-case asymptotic running time complexity is in O( n3 lgn ) and we know that
time proportional to n2 lg(n3lgn) is a lower bound on the worst-case asymptotic
running time complexity of any algorithm solving P. Now, let A be an algorithm that
solves P. For each of the following statements about A below [(1)-(4)] determine
whether or not the statement is consistent with the information provided about the
worst-case asymptotic time complexity of P. For example, for (1), determine
whether or not it is possible for A to have worst-case time complexity in ( n2
lglgn) given that P’s worst-case time complexity is in O(n3 lgn) and is also in ( n2
lg(n3lgn)). Note that when working on (1) you can ignore statements [(2)-(4)].
1) A has worst-case time complexity in (n2 lglgn).
2) A has worst-case time complexity in (n2 lg( n3/lgn )).
3) A has worst-case time complexity in( n3 lglgn ).
4) A has worst-case time complexity in O( n2 2lgn ).
3. (10 points) Recurrence:
Find tight upper and lower asymptotic bounds on the solution to the following
T (n)  2T n  2  n
You may assume that T(2) = 1 and n is even.
page 1 of 2
Explain your answer.
Analysis of Algorithms 91.503 (section 201)
Spring, 2005
4. (10 points) Dynamic Programming: Determine an LCS of these two strings:
<A, B, B, C, B, A, C, A>
<B, C, A, B, B, A, A, C>.
Justify optimality of your answer.
5. (60 points) Dynamic Programming:
Solve the following car painting problem efficiently using dynamic programming: given a
sequence of n cars, each to be painted one of c different colors, and k adjacent positions
each car can move, find a sequence with the minimum number of adjacent color
changes. That is, each car in the final ordering can be at most k positions away from its
original position.
Example: Let n = 9, k = 2 and let 0, 1, 2 represent c = 3 colors. Let the following
sequence represent the starting state:
<0 1 1 2 0 0 1 2 1>
The sequence < 1 1 0 0 0 2 2 1 1 > is an optimal solution. The number of adjacent
color changes in this solution is 3: change from 1 to 0, change from 0 to 2 and change
from 2 to 1.
a. Characterize the structure of the optimal solution.
b. Recursively define the value of an optimal solution.
c. Compute the value of an optimal solution in a bottom-up fashion.
d. Construct an optimal solution from the computed information.
Include in your answer:
- pseudocode written using the conventions on p. 19-20 of the textbook;
- correctness justification;
- upper bound on worst-case asymptotic running time.
page 2 of 2