Quiz 2 CS 3510 October 22, 2004 NAME : (Remember to fill in your name!) For grading purposes, please leave blank: (1) Short Answer (40 points) (2) Cycle Length (20 points) (3) Bottleneck (20 points) (4) 0-1 MST (20 points) (Remember to correctly answer all 4 questions!) 1
Name: 2 Let G = (V, E) be an undirected connected graph with distinct non-negative costs on its edges, and which contains at least n edges. Problem 2(a). [5 points] Let e min be the lowest cost edge, in other words: For all e E, cost(e min ) < cost(e ). Which of the following is true about e min : e min does not belong to any MST (minimum cost spanning tree) of G. e min belongs to every MST (minimum cost spanning tree) of G. e min might belong to some MSTs of G, but it s not guaranteed to belong to all MSTs of G. Problem 2(b). [5 points] Let e max be the highest cost edge, in other words: For all e E, cost(e max ) > cost(e ). Which of the following is true about e max : e max does not belong to any MST (minimum cost spanning tree) of G. e max belongs to every MST (minimum cost spanning tree) of G. e max might belong to some MSTs of G, but it s not guaranteed to belong to all MSTs of G. Problem 2(c). [5 points] Let G = (V, E), V = n, be a DAG (directed acyclic graph), and let v 1 < v 2 <... < v n be a topological sorting of V (so that v i v j E implies v i < v j ). Suppose that we create a graph G by adding a single new edge v k v l to G, for some v k > v l in the topological sorting. Is the following proposition true or false: G always contains a cycle.
Name: 3 Problem 2(d)-(g). We run DFS on a directed graph G = (V, E). Problem 2(d). [5 points] What can we conclude, if anything, about the vertex with highest postorder number (in other words, the vertex which finishes last)? Problem 2(e). [5 points] If G were a DAG (directed acyclic graph), what can we conclude, if anything, about the vertex with highest postorder number (in other words, the vertex which finishes last)? Problem 2(f). [5 points] What can we conclude, if anything, about the vertex with lowest postorder number (in other words, the vertex which finishes first)? Problem 2(g). [5 points] If G were a DAG (directed acyclic graph), what can we conclude, if anything, about the vertex with lowest postorder number (in other words, the vertex which finishes first)? Problem 2(h). [5 points] Given the following Min-Heap structure, perform Decrease-Key of vertex G to 5. Write the new Min-Heap structure.
Name: 4 Problem 3. [20 points] Let G = (V, E), V = n, be a directed graph with positive costs on its edges. Let C be a given positive number. Give an O(n 3 ) time algorithm that determines if G has a cycle of cost smaller than C. In this problem you must give the pseudocode and argue about the running time.
Name: 5 Problem 4. Let G = (V, E) be a directed graph with weights on its edges, and let s V be a specified vertex in V. Let s = v 0 v 1 v 2... v k = u be a path from s to another vertex u. Define the bottleneck of the above path as the weight of the heaviest edge along this path. Now define a min bottleneck path from s to u as a path from s to u whose bottleneck is as small as possible. In other words, we want to find a path from s to u which minimizes the maximum weight edge on the path. Problem 4(a). [10 points] Give an algorithm that finds a min bottleneck path from s to every other vertx u V, by modifying Dijkstra s algorithm. For this part, you only need to show the modifications of the pseudocode on Dijkstra s algorithm. Dijkstra(G, weight, s) 1 for each vertex v V [G] 2 do dist[v] 3 prev[v] nil 4 dist[s] 0 5 H = Create a new heap H 6 for each vertex v V [G] 7 do Insert-Heap(H, v, dist[v]) 8 while H 9 do v Extract-Min(H) 10 for all edges (v, w) E 11 do if dist[w] > dist[v] + weight(v, w) 12 then 13 dist[w] dist[v] + weight(v, w) 14 Decrease-Key(H, w, dist[w]) 15 prev[w] v
Name: 6 Problem 4(b). [10 points] What is the running time of your min-bottleneck resulting algorithm? Give your answer in terms of V and E, and explain your answer (i.e., do not say it is the same as Dijkstra s ).
Name: 7 Problem 5. [20 points] Let G = (V, E) be a connected graph with costs on its edges, and suppose that these costs are either 0 or 1. Give an O( V + E ) time algorithm to find the cost of an MST (minimum cost spanning tree) in G. You may describe your algorithm in English, or give clear pseudocode, and you must argue about the running time. You can use the algorithms presented in class as subroutines without rewriting their pseudocode, but state clearly which algorithm and its running time.
Name: 8
Name: 9
Name: 10
Name: 11