503_HW1

advertisement
UML CS
Analysis of Algorithms 91.503 (section 201)
Fall, 2002
Homework Set #1
Assigned: Tuesday, 9/3
Due: Tuesday, 9/10 (start of lecture)
This assignment covers textbook material in Chapter 15 (Dynamic Programming),
plus review material from 91.404.
1. (20 points) Let P be a problem. Suppose that the worst-case asymptotic running time
complexity of P is in O(n2 lg3n) and is also in ( n2 ). 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 (lgn) given that P’s worst-case time complexity is in
O(n2 lg3n) and is also in ( n2 ). Note that when working on (1) you can ignore statements
[(2)-(4)].
1) A has worst-case time complexity in( lgn ).
2) A has worst-case time complexity in O( lgn ).
3) A has worst-case time complexity in( n2 lg2n ).
4) A has worst-case time complexity in O( n5 lg3n ).
2. (20 points) Function Order of Growth
a) (10 points) Given the four functions:
n3 lg n
n lg 3 n
1
 
5
32 log9 n
2n
Arrange the 4 functions in order of increasing asymptotic size.
b) (10 points) Given the following facts about 4 functions f1(n) , f2(n) , f3(n) , f4(n) :

f1 (n)   n 3 lg n


f 2 (n)   n lg 3 n

Can we conclude that
f 4 (n)  ( f1 (n)) ?
Why or why not?
1

f 3 (n)   32 log9 n

  1 2
f 4 (n)    
 5 

n




UML CS
Analysis of Algorithms 91.503 (section 201)
Fall, 2002
3. (10 points) Dynamic Programming: Textbook, p. 355, Exercise 15.4-1.
4. (50 points) Dynamic Programming: Smallest Common Supersequence
The Longest Common Subsequence (LCS) problem is defined in our textbook in Section 15.4
(p. 350-355). Using the same definition of sequence, subsequence, and common
subsequence, we can define the Smallest Common Supersequence of two strings as follows:
The Smallest Common Supersequence of two sequences X and Y is the smallest sequence Z
such that both X and Y are subsequences of Z.
In this problem, you’ll design an efficient algorithm that finds the smallest common
supersequence of two sequences X and Y.
Your algorithm should accept, as input, two sequences of characters X and Y. Your algorithm
should output a sequence of characters Z that is the smallest common supersequence of X and
Y.
Assume that each sequence, X, Y, and Z is a string of characters stored in an array. Use the
textbook’s array conventions:
- length[A] is the number of elements in array A
- A[ i ] accesses the ith element of array A
- array elements are numbered starting with index 1
a. (20 points) Provide pseudocode for your algorithm.
(Hint: Consider the edit distance between X and Y and also the LCS of X and Y.)
(Note: If you use a slight variation on some algorithm in our text or (problems in the text), you
need not include that pseudocode; just describe the variation in sufficient detail to allow
correctness and running time to be justified in parts (b) and (c).)
b. (15 points) Prove the correctness of your pseudocode and algorithm.
c. (15 points) Analyze the running time of your pseudocode and algorithm to obtain an upper
bound on the worst-case asymptotic running time.
2
Download