advertisement

CSE 431/531 Homework 3 Due date: Mar 21, 2016 Lecturer: Shi Li Your Name: Your University ID: Problems Max. Score Your Score 1 6 2 6 3 16 4 12 Total Score 40 Problem 1 (6 points). Longest path problem in directed acyclic graphs (DAGs). We are given a directed acyclic graph G. For simplicity, assume the vertices of G are {1, 2, · · · , n} and G contains m edges. The m edges are given by m tuples of the form (i, j, c), where each tuple (i, j, c) defines a directed edge of value c from vertex i to vertex j. We assume all tuples (i, j, c) satisfy 1 ≤ i < j ≤ n and c > 0. The goal of the problem is to compute a path from 1 to n with the maximum total value. Design an O(m)-time algorithm for the problem. Problem 2 (6 points). Given an instance of the weighted interval scheduling problem with n jobs, show how to construct an equivalent instance of the longest-path problem defined in Problem 1. You can assume the n jobs are indexed according to the non-decreasing order of finishing times. Your instance for the longest-path problem should have O(n) vertices and O(n) edges. (In class, you have seen a reduction to instances with O(n) vertices and O(n2 ) edges.) Problem 3 (16 points). Given a sequence A = (a1 , a2 , · · · , an ) of n numbers, we need to find the maximum-length increasing subsequence of A. That is, we want to find a maximum-length sequence (i1 , i2 , · · · , it ) of integers such that 1 ≤ i1 < i2 < i3 < · · · < it ≤ n and ai1 < ai2 < ai3 < · · · < ait . 1. (8 points) Design an O(n2 )-time algorithm for the problem. 2. (8 points) Design an O(n lg n)-time algorithm for the problem. Problem 4 (12 points). An independent set of a graph G = (V, E) is a set U ⊆ V of vertices such that there are no edges between vertices in U . Given a graph with node weights, the maximumweight independent set problem asks for the independent set of a given graph with the maximum total weight. In general, this problem is very hard. Here we want to solve the problem on trees: given a tree with node weights, find the independent set of the tree with the maximum total weight. For example, the maximum-weight independent set of the tree in Figure 1 has weight 47. Design an O(n)-time algorithm for the problem, where n is the number of vertices in the tree. We assume that the nodes of the tree are {1, 2, 3, · · · , n}. The tree is rooted at vertex 1, and for each vertex i ∈ {2, 3, · · · , n}, the parent of i is a vertex j < i. In the input, we specify the weight wi for each vertex i ∈ {1, 2, 3, · · · , n} and the parent of i for each i ∈ {2, 3, · · · , n}. 1 15 16 8 3 5 5 18 7 2 9 4 Figure 1: The maximum-weight indpendent set of the tree has weight 47. The red vertices give the independent set. 2