q2-f2008-sol

q2-f2008-sol - November 12, 2008 6.006 Fall 2008 Quiz 2...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms November 12, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Quiz 2 Solutions Quiz 2 Solutions Problem 1. BFS/DFS [10 points] (2 parts) Give the visited node order for each type of graph search, starting with s , given the following ad- jacency lists and accompanying figure: adj ( s ) = [ a,c,d ] , adj ( a ) = [ ] , adj ( c ) = [ e,b ] , adj ( b ) = [ d ] , adj ( d ) = [ c ] , adj ( e ) = [ s ] . s a e c b d (a) Breadth First Search Solution: s a c d e b (b) Depth First Search Solution: s a c e b d
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.006 Quiz 2 Solutions Name 2 Problem 2. Miscellaneous True/False [30 points] (10 parts) For each of the following questions, circle either T (True) or F (False). Explain your choice. (No credit if no explanation given.) (a) T F While running DFS on a directed graph, if from vertex u we visit a finished vertex v , then the edge ( u,v ) is a cross-edge. Explain: Solution: False. The edge could be either a cross-edge or a forward edge. Note: The edge cannot be a back edge—a back edge goes to a vertex that has started, but not finished (a “gray vertex”, in CLRS terms). (b) T F Changing the RELAX function to update if d [ v ] d [ u ] + w ( u,v ) (instead of strictly greater than) may produce different shortest paths, but will not affect the correctness of the Bellman-Ford outputs d and π . Explain: Solution: False. The parent pointers may not lead back to the source node if a zero-length cycle exists. In the example below, relaxing the ( s,a ) edge will set d [ a ] = 1 and π [ a ] = 1 . Then, relaxing the ( a,a ) edge will set d [ a ] = 1 and π [ a ] = a . Following the π pointers from t will no longer give a path to s , so the algorithm is incorrect. t a s 1 1 0
Background image of page 2
6.006 Quiz 2 Solutions Name 3 (c) T F The running time of Radix sort is effectively independent of whether the input is already sorted. Explain: Solution: True. All input orderings give the worst-case running time; the run- ning time doesn’t depend on the order of the inputs in any significant way. (d) T F Let P be a shortest path from some vertex s to some other vertex t in a directed graph. If the weight of each edge in the graph is increased by one, P will still be a shortest path from s to t . Explain: Solution: False. See the counterexample below. b a t s 1 4 1 1 (e) T F If a weighted directed graph G is known to have no shortest paths longer than k edges, then it suffices to run Bellman-Ford for only k passes in order to solve the single-source shortest paths problem on G . Solution: True. The i th iteration finds shortest paths in G of i or fewer edges, by the path relaxation property (see p. 587 in CLRS).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.006 Quiz 2 Solutions Name 4 (f) T F If a topological sort exists for the vertices in a directed graph, then a DFS on the graph will produce no back edges.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the 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.

Page1 / 12

q2-f2008-sol - November 12, 2008 6.006 Fall 2008 Quiz 2...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online