Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.

Similar presentations


Presentation on theme: "Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question."— Presentation transcript:

1 Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question 1. (20 points) Give an O(n 2 ) 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.

2 Assignment 4. (Due on Dec 2. 2:30 p.m.) Question 2. (40 points) Give an O(n 2 ) 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.

3 Assignment 4. (Due on Dec 2. 2:30 p.m.) 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 polynomial-time dynamic programming algorithm to solve the problem.

4 A A C Figure 1

5 Lemma 26.8: If the Edmonds-Karp algorithm is run on a flow network G=(V,E) with source s and sink t, then for all vertices v  V-{s, t}, the shortest-path distance  f (s,v) in the residual network G f increases monotonically with each flow augmentation. Proof: We prove it by contradiction. Let f and f’ be the flows for the k-th and (k+1)-th iterations, the augmentation between them is the first that decrease some shortest-path distance. Let v be the vertex with minimum  f’ (s,v) such that  f’ (s,v)<  f (s,v).

6 Let P: s -- … u->v be the shortest path in G f’. Thus, (u,v)  E f’ and  f’ (s,u)=  f’ (s,v)-1. By the choice of v,  f’ (s,u)   f (s,u). Thus, (u,v)  E f. (Otherwise, we have  f (s,v)   f (s,u)+1   f’ (s,u)+1 =  f’ (s,v). ) How can we have (u,v)  E f’ and (u,v)  E f. ? The augmentation must have increased the flow form v to u.

7 Since E-K algorithm always uses shortest path, edge (v, u) is the last edge in the path from s to u. So,  f (s,v)=  f (s,u)-1   f’ (s,u)-1 =  f’ (s,v)-2. Contradiction to  f’ (s,v)<  f (s,v).

8 Theorem 26.9. If Edmonds-Karp algorithm is run on a flow network G=(V,E) with source and sink t, then the total number of flow augmentations performed by the algorithm is O(VE). Proof: Each augmentation has a critical edge (u, v), where c(u,v) is minimum among all edges in the shortest path. We show that each edge (u,v) can be a critical edge for at most O(|V|) times. Consider a critical edge (u,v) for flow f.  f (s,v)=  f (s,u)+1. (u,v) will disappear after that path is used for augmentation.

9 (u,v) will appear again after an augmentation with (v,u) in the shortest path. Let f’ be the flow in G when this event occurs, we have  f’ (s,u)=  f’ (s,v)+1. Thus,  f’ (s,u)=  f’ (s,v)+1   f (s,v)+1=  f (s,u)+2. Since the length of the shortest path is at most |V|-1. Thus, each edge (u,v) can be a critical edge for at most |O(|V|) times. Total number of augmentations is O(VE). Each iteration takes at most O(E) time, the total time is O(VE 2 ).

10 Maximum k-Clustering Problem: Given a set of points V in the plane (or some other metric space), find k points c 1, c 2,.., c k such that for each v in V, min { i=1, 2, …, k} d(v, s i )  d and d is minimized.

11 Fasthest-point clustering algorithm Step 1: arbitrarily select a point in V as c 1. Step 2: let i=2. Step 3: pick a point c i from V –{c 1, c 2, …, c i-1 } to maximize min {|c 1 c i |, |c 2 c i |,…,|c i-1 c i |}. Step 4: i=i+1; Step 5: repeat Steps 3 and 4 until i=k.

12 Theorem: Farthest-point clustering algorithm has ratio-2. Proof: Let c k+1 be an point in V that maximize  =min {|c 1 c k+1 |, |c 2 c k+1 |,…,|c k c k+1 |}. Since two of the k+1 points must be in the same group,  <=2opt. Since for any v in V, min {|c 1 v|, |c 2 v|,…,|c k v|}<=  (based on the alg.), so the algorithm has ratio-2.


Download ppt "Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question."

Similar presentations


Ads by Google