EECS 336 Problem Set 3 Due date: Feb 10, 2015 Lecturer: Shi Li Your Name: Your University ID: Problems Max. Score Your Score 1 20 2 30 3 20 4 20 Total Score 80 The sum of the maximum scores of the 4 problems is 90. Your final score for this problem set will be 80 if you get more than 80 points. This score will be scaled by 0.1 and added to your final score for the course. Problem 1 (20 points). Let G = (V, E) be a directed graph and w : E → R be a weight function. Let a : V → R be a function on V . Then we define wa : E → R to be a new weight function such that wa (u, v) := w(u, v) + a(u) − a(v) for every edge (u, v) ∈ E. 1. (10 points) Prove that for any u, v ∈ V , any shortest path from u to v in the weighted graph (G, w) is also a shortest path from u to v in the weighted graph (G, w0 ). 2. (10 points) Show that if (G, w) does not contain a negative cycle, then there is a function a such that wa (u, v) ≥ 0 for every (u, v) ∈ E. Problem 2 (30 points). (a) (20 points) Problem 15-2 on Page 405 of the textbook (longest palindrome subsequence). (b) (10 points) Suppose the goal of the problem is to compute the length of the longest palindrome (you do not need to give a longest palindrome). Give a O(n2 )-time O(n)space algorithm that computes the length of the longest palindrome. (n is the length of the input string.) Problem 3 (20 points). Let G = (V, E) be a directed acyclic graph. Assume V = {1, 2, 3, · · · , n} and all edges (i, j) ∈ E has i < j. Let w : E → R be a weight function. We say a path is an even path if it contains an even number of edges. Give a O(E) time algorithm that computes the shortest even path from 1 to n. Problem 4 (20 points). Let T = (V, E) be a tree rooted at r and w : V → R>0 be a weight function on vertices of T . Your goal is to compute the maximum-weight sub-graph T 0 of T , 1 such that T 0 is a tree rooted at r of degree at most 2. Give a dynamic programming algorithm that computes the weight of T 0 . For example, for the following tree T , the maximum-weight sub-graph T 0 satisfying the requirement has weight 227, as indicated by the yellow vertices and red edges. 15 20 13 20 40 60 18 25 50 30 17 32 20 For simplicity, you may assume V = {1, 2, 3, · · · , n} and a child i of a vertex j has i < j. (Thus, the root is n). 2
© Copyright 2024