Download assig4

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Large numbers wikipedia , lookup

Addition wikipedia , lookup

Sequence wikipedia , lookup

Collatz conjecture wikipedia , lookup

Algorithm wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
CS3335 Design and Analysis of Algorithms
Assignment 4. (Due on Dec 2. 2:30 p.m.)
Question 1. (20 points) Give an O(n2) dynamic algorithm to find the longest
monotonically increasing subsequence of a sequence of n numbers. (Assume that each
integer appears once in the input sequence of n numbers)
Example: Consider sequence 1,8, 2,9, 3,10, 4, 5. Both subsequences 1, 2, 3, 4, 5 and 1,
8, 9, 10 are monotonically increasing subsequences. However, 1,2,3, 4, 5 is the longest.
Question 2. (40 points) Give an O(n2) dynamic algorithm to find the longest
monotonically increasing subsequence of a sequence of n numbers, where an odd
number in the monotonically increasing subsequence must be followed by an even
number.
Example: Consider sequence 1,7,8, 2,9, 3,10, 4, 5. Both subsequences 1, 2, 3, 4, 5 and 1,
8, 9, 10 are monotonically increasing subsequences. However, 1,2,3, 4, 5 is not the one
that we are looking for since 5 is not followed by an even number.
Question 3 (40 points) Let T be a rooted binary tree, where each internal node in the
tree has two children and every node (except the root) in T has a parent. Each leaf in the
tree is assigned a letter in ={A, C, G, T}. Figure 1 gives an example. Consider an edge
e in T. If every end of e is assigned a letter, then the cost of e is 0 if the two letters are
identical and the cost is 1 if the two letters are not identical. The problem here is to
assign a letter in  to each internal node of T such that the cost of the tree is minimized,
where the cost of the tree is the total cost of all edges in the tree. Design a dynamic
programming algorithm to solve the problem.
A
A
C
Figure 1