This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology Professors Shaﬁ Goldwasser and Silvio Micali October 31, 2003 6.046J/18.410J Handout 19 Problem Set 6
This problem set is due in recitation on Friday, November 14. Reading: Chapters 17.117.4, 22.122.5, 23.123.2, 24.124.5. There are four problems and one exercise. You should only hand in Problems 6.1 through 6.4. The ﬁrst exercise is for review purposes and will not be graded. Each problem is to be done on a separate sheet (or sheets) of threehole punched paper. Mark the top of each sheet with your name, the course number, the problem number, your recitation section, the date, and the names of any students with whom you collaborated. Exercise 61. Graphs: Terminology and Deﬁnitions Note: This problem is not to be handed in. A graph is a set of vertices, , and edges, . In this problem, we will review some basic properties of graphs. For each question, answer True or False or ﬁll in the blank where indicated. Justify your answers. (It may be useful to refer to Section B.4 in CLRS.) (a) An undirected acyclic graph contains (b) A directed acyclic graph contains (c) A dense graph contains (d) Let edges. edges. edges. be an undirected graph. If , then (e) If a graph is sparse, then it is a tree. (f) For every directed graph, there is a unique topological sort. (g) A graph is connected iff it contains a cycle. (h) Every undirected graph has a minimum spanning tree. (i) A directed acyclic graph is not strongly connected. (j) A directed acyclic graph contains a vertex (k) If there is a directed path from to connected component. such that . in a directed graph, then vertices and (l) Suppose we have a directed graph that is strongly connected. For any depthﬁrst search of , if all the forward edges of (with respect to the depthﬁrst forest) are removed from , the resulting graph is still strongly connected. UT ¡ S ¢¤ G©D%ERQPBIC ¤ F ¢ ¤C 8 4 $#"HG©D%ED2BA@97653 ¦¦ ¡ ¨¤¢ ©§¦WV¡ E ¤ $%"! ¤ $#"! ¦ UT &&&&&&& '''''''& ¡ ¡ ¨¤¢ 210¦)(¡ ¨¤¢ ©§¦¥£¡ is dense. form a 2 Problem 61. Cycles Handout 19: Problem Set 6 (a) Give an algorithm to ﬁnd a minimum weight cycle in a given weighted, undirected, connected graph in which all edge weights are nonnegative. Prove your algorithm is correct and analyze its running time. (Optional Extra Credit Problem: Can you ﬁnd a more efﬁcient algorithm for this problem?) (b) Give an algorithm to determine if a given directed, connected graph contains an edge that is in every cycle. Prove your algorithm is correct and analyze its running time. (Optional Extra Credit Problem: Can you ﬁnd a more efﬁcient algorithm for this problem?) (c) Suppose that a weighted, directed graph has a negativeweight cycle. Give an efﬁcient algorithm to list the vertices of one such cycle. Prove your algorithm is correct and analyze its running time. Problem 62. Minimum Spanning Trees (a) Consider the following algorithm, N EWMST, for computing a minimum spanning tree. The algorithm takes as input an undirected, weighted, connected graph . It sorts the edges in nonincreasing order according to edge weight. It then goes through each edge in , in the sorted order, and determines if removing that edge disconnects the graph. If not, then the edge is removed permanently, otherwise the edge remains. Below, we provide pseudocode for the N EWMST algorithm. Prove that the N EWMST algorithm outputs a minimum spanning tree of the input graph . (b) Give an efﬁcient algorithm to ﬁnd a spanning tree for a connected, weighted, undirected graph such that the weight of the maximumweight edge in the spanning tree is minimized. Prove your algorithm is correct. Problem 63. Labeled Graphs and Longest Paths You are given a directed graph , in which each vertex has a unique label a cost function assigning a weight to each edge, and a source . Additionally, has the property that . Design an algorithm to construct an output array every edge such that is the length of the longest path from to in . ¦ ¤ D#Eg pqep¨piBiBi¨ X eh¨ge f N EWMST( ) 1 Sort edges according to edge weight in nonincreasing order: 2 3 While : 4 If is connected 5 6 7 Output . ¡ ¦d fe ¡ rE ¨ d10¦¤ ¢ ¡ ¤ l ¤ iUajnmk%Tj ( %qiT fg¨hUp o#T¤ ¨¤¢ d10¦
¡ t¡T sT r pew¡ r x p(¡ y¡ e x vu w1T ¦ YX ¤ ba`'2%HF ¡ ¡ ¡ ¤ c§¦HF t sT r ¡ ¨ o Handout 19: Problem Set 6
Problem 64. Amortized WeightBalanced Trees 3 Consider an ordinary binary search tree augmented by adding to each node the ﬁeld giving the number of keys stored in the subtree rooted at . Let be a constant in the range . We say that a given node is balanced if and The tree as a whole is balanced if every node in the tree is balanced. We will study the following amortized approach to maintaining weightbalanced trees. (a) Given a node in an arbitrary binary search tree, show how to rebuild the subtree rooted at so that it becomes balanced. You algorithm should run in time time and can use auxiliary storage. (b) Show that performing a search in an worstcase time. node balanced binary search tree takes For the remainder of this problem, assume that the constant is strictly greater than . Suppose that I NSERT and D ELETE are implemented as usual for an node binary search tree, except that after every such operation, if any node in the tree is no longer balanced, then the subtree rooted at the highest such node in the tree is “rebuilt” so that it becomes balanced. We shall analyze this rebuilding scheme using the potential method. For a node in a binary search tree , we deﬁne and we deﬁne the potential of as where is a sufﬁciently large constant that depends on . (c) Argue that any binary search tree has nonnegative potential and that a balanced tree has potential 0. (d) Suppose that units of potential can pay for rebuilding an node subtree. How large must be in terms of in order for it to take amortize time to rebuild a subtree that is not balanced. (e) Show that inserting a node into or deleting a node from an node balanced tree costs amortized time. qe 's p jktBT f X s s f X u u X ¢ ¨#s¤ }
h s h@ 1#¤ ¨Qq's p 990T yp rktBTaq's p {ze xp rktBTy1s¤ q  e q  e ¢ " ¤ v {QtF u X f u" u 0iq's p j§tBT7~vsq's p 9%T p jktBT e } u u q  e q's p jktBT7~vsaq's p {ze yxp jktBT e }uuq  e us s u u " q'X s j§tT0HF e¤ fp u u u ss v "` ¤ ©ja %YHF " ¤ ©`%YF
's p j§tBT§! qe¤ tlu Gwvu fX ...
View Full
Document
 Fall '01
 CharlesE.Leiserson
 Algorithms

Click to edit the document details