This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Introduction to Algorithms April 14, 2010 Massachusetts Institute of Technology 6.006 Spring 2010 Professors Piotr Indyk and David Karger Quiz 2 Solutions Quiz 2 Solutions Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either T (True) or F (False). There is no penalty for incorrect answers. (a) T F [3 points] For all weighted graphs and all vertices s and t , BellmanFord starting at s will always return a shortest path to t . Solution: FALSE. If the graph contains a negativeweight cycle, then no short est path exists. (b) T F [3 points] If all edges in a graph have distinct weights, then the shortest path between two vertices is unique. Solution: FALSE. Even if no two edges have the same weight, there could be two paths with the same weight. For example, there could be two paths from s to t with lengths 3 + 5 = 8 and 2 + 6 = 8 . These paths have the same length ( 8 ) even though the edges ( 2 , 3 , 5 , 6 ) are all distinct. (c) T F [3 points] For a directed graph, the absence of back edges with respect to a BFS tree implies that the graph is acyclic. Solution: FALSE. It is true that the absence of back edges with respect to a DFS tree implies that the graph is acyclic. However, the same is not true for a BFS tree. There may be cross edges which go from one branch of the BFS tree to a lower level of another branch of the BFS tree. It is possible to construct a cycle using such cross edges (which decrease the level) and using forward edges (which increase the level). 6.006 Quiz 2 Solutions Name 2 (d) T F [3 points] At the termination of the BellmanFord algorithm, even if the graph has a negative length cycle, a correct shortest path is found for a vertex for which shortest path is welldefined. Solution: TRUE. If the shortest path is well defined, then it cannot include a cycle. Thus, the shortest path contains at most V 1 edges. Running the usual V 1 iterations of BellmanForm will therefore find that path. (e) T F [3 points] The depth of any DFS tree rooted at a vertex is at least as much as the depth of any BFS tree rooted at the same vertex. Solution: TRUE. Since BFS finds paths using the fewest number of edges, the BFS depth of any vertex is at least as small as the DFS depth of the same vertex. Thus, the DFS tree has a greater or equal depth. (f) T F [3 points] In bidirectional Dijkstra, the first vertex to appear in both the for ward and backward runs must be on the shortest path between the source and the destination. Solution: FALSE. When a vertex appears in both the forward and backward runs, it may be that there is another vertex (on a different path) which is fur ther away from the source but substantially closer to the destination. (This was covered in recitation.) (g) T F [3 points] There is no edge in an undirected graph that jumps more than one level of any BFS tree of the graph....
View
Full
Document
This note was uploaded on 01/20/2012 for the course CS 6.006 taught by Professor Erikdemaine during the Fall '08 term at MIT.
 Fall '08
 ErikDemaine
 Algorithms

Click to edit the document details