These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

Similar documents
Problem Set 2 Solutions

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

CSE 331: Introduction to Algorithm Analysis and Design Graphs

Dijkstra s algorithm for shortest paths when no edges have negative weight.

7.3 Spanning trees Spanning trees [ ] 61

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Week 11: Minimum Spanning trees

22 Elementary Graph Algorithms. There are two standard ways to represent a

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

CS521 \ Notes for the Final Exam

Solution for Homework set 3

22 Elementary Graph Algorithms. There are two standard ways to represent a

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models.

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

Matching Theory. Figure 1: Is this graph bipartite?

Lecture 8: The Traveling Salesman Problem

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

tree follows. Game Trees

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

Discrete mathematics

Kruskal s MST Algorithm

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

CSE 421 Applications of DFS(?) Topological sort

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

K 4 C 5. Figure 4.5: Some well known family of graphs

Shortest Path Problem

CMPSCI 250: Introduction to Computation. Lecture #22: Graphs, Paths, and Trees David Mix Barrington 12 March 2014

Notes for Recitation 8

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Notes 4 : Approximating Maximum Parsimony

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Treewidth and graph minors

In this lecture, we ll look at applications of duality to three problems:

1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)

Distributed minimum spanning tree problem

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

Chapter 23. Minimum Spanning Trees

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Algorithms for Minimum Spanning Trees

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

We ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Solutions to In-Class Problems Week 4, Fri

CMPSCI 311: Introduction to Algorithms Practice Final Exam

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Analysis of Algorithms, I

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Algorithms For Inference Fall 2014

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

2. Lecture notes on non-bipartite matching

FINAL EXAM SOLUTIONS

Minimum Spanning Trees

Greedy Algorithms 1. For large values of d, brute force search is not feasible because there are 2 d

COMP 355 Advanced Algorithms

Week 12: Minimum Spanning trees and Shortest Paths

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Optimization I : Brute force and Greedy strategy

11.9 Connectivity Connected Components. mcs 2015/5/18 1:43 page 419 #427

Broadcast: Befo re 1

On the Relationships between Zero Forcing Numbers and Certain Graph Coverings

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

Shortest path problems

Practice Problems for the Final

INDIAN STATISTICAL INSTITUTE

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

Ma/CS 6b Class 26: Art Galleries and Politicians

Greedy Algorithms. Previous Examples: Huffman coding, Minimum Spanning Tree Algorithms

CSE 521: Design and Analysis of Algorithms I

All-to-All Communication

Paths, Flowers and Vertex Cover

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Theorem 2.9: nearest addition algorithm

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

09 B: Graph Algorithms II

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )

Exam 3 Practice Problems

Chapter 3: Paths and Cycles

Assignment # 4 Selected Solutions

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

1 The Shortest Path Problem

Lecture 22 Tuesday, April 10

implementing the breadth-first search algorithm implementing the depth-first search algorithm

(Refer Slide Time: 00:18)

Reference Sheet for CO142.2 Discrete Mathematics II

COL 702 : Assignment 1 solutions

Transcription:

CSE 591 HW Sketch Sample Solutions These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions. Problem 1 (a) Any arc that pointing to s, i.e., incoming arcs of s, cannot be needed in T s. Since s is the root of the tree and all arcs have positive length, its distance won t be updated in Dijkstra s algorithm. Hence such arcs will never be used. Now look at the subtree rooted at s in T s. The paths from s to all vertices in this subtree are necessarily shortest paths, so we can eliminate from consideration all arcs that enter any one of the vertices in this subtree, and finalize the distances to each of these vertices. Without knowing anything at all about the arc lengths, it appears that no other arcs can be excluded with certainty in advance (compare the cases when the arcs out of s not appearing in T s have very short length versus the case where they have very long length). (b) Let N s = {v (s, v) A}, N s = {u (s, u) A}. We claim if N s = N s and for all v N s and length(s, v) = length(s, v), then for every vertex other than s and s has the same distance from the root in both trees. Let s recall the procedure of Dijkstras algorithm, the distances of root s neighbors will be updated in the first iteration. Hence, if both s and s have the same neighbor and arcs with same length, the results of first iteration of Dijkstra s algorithm will also be the same. Continuing the procedure, all other vertices end up getting the same distance. (c) We find large classes of examples here, not a characterization. Whenever the shortest paths from s do not go through s and vice versa, the paths should be arc-disjoint. So pick any directed graph in which s can reach all other vertices; remove all arcs into s; compute the minimum arc length M, and the sum of all the arc lengths, B; add a new vertex s and an arc from s to every other vertex of length M/; and add an arc from s to s having length B + 1. Every shortest path from s does not go through s and vice versa, so we have found a very large class of examples. Millions of other answers are possible (and just as good). Problem (a) Let S be set of servers, C be set of clients. Add a new vertex s, and add arcs from s to each vertex in S; each arc has delay 0 (if permitted, otherwise use some small value ε, and add ε to δ). Algorithm 1 run Dijkstra s algorithm using s as source, to produce tree T s. 1

for (each c in C) do if (there is a path from s to c in T s, say P c ) then if P c > δ then output false else output false output true. Assuming there are m edges, the running time of above algorithm is O(m+( S + C ) log ( S + C )) when using min-heap for Dijkstra s algorithm. (b) Two possible solutions. Here is the first. We prove by contradiction. Suppose for one particular client c, our algorithm says there is no such path but the result is wrong. Then there exists a path from certain server s to c, say P s,c such that P s,c δ. However, in our algorithm, at certain iteration we must use s as the source node and compute shortest path tree. By validity of Dijkstra s algorithm (which should be explained for completeness), we must get a path with length no greater than P s,c, hence no greater than δ. This is a contradiction, therefore our algorithm works correctly and there is no such path indeed. Here is the second (sketch only). One could prove that there is a vertex c C for which there is no path from s to c with total delay at most δ as follows. If no path exists from s to c, I would show a single cut with s on one side, c on the other, so that no arc crosses the cut from s s side to c s. If a path P c does exist, say it is (s = x 0, x 1,..., x l 1, x l = c). Suppose that the delays calculated from s (in T s ) are d 0, d 1,..., d l. Consider the cuts C 0,..., C l 1, where C i splits the vertices into one side containing s that contains all vertices whose delay from s is less than d i and all vertices other than x i+1 whose delay is d i ; the other side contains all remaining vertices. Then I verify that the lowest delay edge in the arc cutset for C i is the edge from x i to x i+1. But every path from s to c must cross all of these cuts. Problem 3 (a) First, for each task T i, we create a vertex v i. If T i is precedence requirement of T j, we create an directed arc (v i, v j ). Let the resulting graph be G, with G = n. We claim that all tasks can be done if and only if there is no directed cycle in G, i.e., G is an directed acyclic graph(dag). Sufficiency: there is no directed cycle in G => all tasks can be completed. Proof. We prove by induction on G. Base case: G = 1. It is trivial case and the only task can be done. Induction step: G > 1. Firstly, we want to show there is a vertex, say u, which has in-degree 0, i.e., no arc points to u. Let P the longest directed path in G, we

claim the starting vertex of P is a candidate for u. Suppose not, there is an arc (w, u), if w is on P, we have a directed cycle, contradicting assumption. Otherwise, w is not on P and we get a longer path w > P, also a contradiction. Hence, there exists such vertex u. By the rule we construct G, u s corresponding task, say T u, has no precedence requirement and can be done at the very beginning. Let G = G u, noting that removing one vertex won t create any cycle, hence G is also a DAG. By induction hypothesis, all tasks remaining can be completed, together with T u, we are able to finish all tasks. Necessity: all tasks can be completed => there is no directed cycle in G. Proof. Suppose not, there is a directed cycle C and a schedule that all tasks can be done according to the schedule. Let u be the vertex whose corresponding task, T u, starts first among all vertices in C. Let s look at u s predecessor in C, say v and its corresponding task T v. By the choice of u, T v starts no earlier than T u, but since T v is T us precedence requirement, T u cannot start until T v is done, contradicting T u starts first. Therefore, no such u exists and hence no directed cycle exists. (b) It just asked for an efficient algorithm, not the most efficient. One could modify the idea in Dijkstra s algorithm, but this solution uses a more direct (if less efficient) approach. Algorithm ans = 0 for (each task T i ) do T i.start = 0 while (G is not empty) do Find a vertex u whose in-degree is 0 Say T u be its corresponding assignment. if (T u has no precedence requirement) then T u.start = 0, T u.end = T u.duration else for (each T v that T v is a precedence of T u ) do T u.start = max(t u.start, T v.end) T u.end = T u.start + T u.duration ans = max(ans, T u.end) remove u from G end while output ans The complexity of running time is O(n log n), the outer while loop takes O(n) time. We can use a min-heap to identify u each time, it takes O(log n) time. Then, it takes O(n) time to determine T us start time and remove it from G, hence the asymptotic running time is O(n log n). 3

Next we show the correctness of our algorithm. It suffices to claim every tasks starts at the earliest possible time. Proof. We prove on induction on n. Base step: n = 1. It is trivial case and true. Induction step: n > 1. Let the task which finishes last be T u. First, we show T u is not precedence requirement for any other task. Suppose not, another task, say T v should start after when T u is finished. In this case, T v will finish later than T u, contradicting choice of T u. Hence, it is safe to remove u from G and all other tasks can be complete since no other tasks depend on T u. By induction hypothesis, we make every task start as early as possible by running our algorithm on G u. Then we put u back, if u has no precedence, it can start at time 0. Otherwise, it should start after all its precedence requirements have been finished. And our algorithm checks for the latest time when its precedence completes and we have shown it is the earliest time when its precedence can be done. Hence, u also starts at the earliest possible time and our algorithm must get optimal solution. (c) We already get a schedule in (b) and can use that for (c). Problem 4 W.l.o.g., we assume the input graph is G = (V, E) Generalized Kruskal s algorithm F = Sort all edges by their lengths in nonincreasing order for (each edge (u, v) E) do if (length(u, v) > 0 and (u, v) does not create a cycle in F) then Add (u, v) to F Time complexity of generalized Kruskal s algorithm is O( E log V ) which is the same as normal Kruskal s algorithm. In order to show F is a maximum spanning forest, we need to show two things: (1) F contains no cycle and () the total weight of F is maximum. (1) is naturally true since when picking edges, we always avoid creating a cycle. For (), we can apply the similar argument for minimal spanning tree. Clearly, edges with negative cost should be abandoned. Let F be one maximum forest of G, if F and F are the same, then we are done. Otherwise, there is an edge e F that is not contained in F. Consider F + e, there must be a cycle C. Here we should observe that: (a). Every other edges in C has weight no less than e. It is true by the rule we construct F, edges with longer length are selected first. (b). There is some edge f in C that is not included in F. Let F = F + e f, we have a new forest and have more common edges with F than F. We can continue this process until we get F. Noting that, each time we replace f by e. we do not increase the weight, it is true by (a). Therefore, we have the following 4

relation w(f ) w(f )... w(f ). Since F is one maximum forest, then F must also be a maximum forest. Problem 5 W.l.o.g, we assume input graph is G = (V, E) and V = n. We also suppose that all edges whose weights are not positive (if any) have been removed, because they will never be selected. (a) We may assume the input format is edge list. First, we need four hashset to store A, B, C, D. in order to run Generalized Kruskal s algorithm, we need disjoint set to check whether it will create a cycle by adding some edges. Also, we need an extra list to store selected edges after running Generalized Kruskal s algorithm. (b) As mentioned in 4, the running time Kruskal s algorithm is O( E log V ) = O(m log n). For combining part, there are at most 6 ( n 1) = 3n 6 edges left, plugging in this value, the running time is O((3n 6) log n) which is O(n log n). Since we run the algorithm recursively on the 6 forests, we have T (n) = 6 T ( n)+ O(n log n), applying master theorem, we have T (n) = O(n log 6 ). (c) Yes, it generates a maximum weight spanning forest. We rely on the proof in Problem 4. To the contrary, consider the graph G with the fewest vertices for which there is an edge e so that generalized Kruskal s algorithm must select e for inclusion, but e is not chosen in any of the induced subgraphs. Without loss of generality, e is in the induced subgraph on A B but is not selected in its spanning forest. Then e must be a minimum weight edge on some cycle in the induced subgraph, and therefore is also a minimum weight edge on some cycle in G. As we saw in class (in the case when all weights are distinct), there must therefore be a maximum weight forest of G that does not include e, which contradicts our assumptions about G and e. Hence the method must generate a maximum weight spanning forest. 5