{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

q2-f2008-sol

# q2-f2008-sol - 6.006 Fall 2008 Quiz 2 Solutions...

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

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 ﬁgure: 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

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

View Full Document
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 ﬁnished 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 ﬁnished (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
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 signiﬁcant 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 sufﬁces 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 ﬁnds shortest paths in G of i or fewer edges, by the path relaxation property (see p. 587 in CLRS).

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

q2-f2008-sol - 6.006 Fall 2008 Quiz 2 Solutions...

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

View Full Document
Ask a homework question - tutors are online