This preview shows page 1. Sign up to view the full content.
Unformatted text preview: and
breadthﬁrst search ﬁnds it.
(g) T F [2 points] In a weighted undirected tree G = (V, E, w), depthﬁrst search from
a vertex s ﬁnds singlesource shortest paths from s (via parent pointers) in O(V +
E ) time.
Solution: True. In a tree, there is only one path between two vertices, and
depthﬁrst search ﬁnds it.
(h) T F [2 points] If a graph represents tasks and their interdependencies (i.e., an edge
(u, v ) indicates that u must happen before v happens), then the breadthﬁrst
search order of vertices is a valid order in which to tackle the tasks.
Solution: No, you’d prefer depthﬁrst search, which can easily be used to produce a topological sort of the graph, which would correspond to a valid task
order. BFS can produce incorrect results.
(i) T F [2 points] Dijkstra’s shortestpath algorithm may relax an edge more than once
in a graph with a cycle.
Solution: False. Dijkstra’s algorithm always visits each node at most once; this
is why it produces an incorrect result in the presence of negativeweight edges. (j) T F [2 points] Given a weighted directed graph G = (V, E, w) and a source s ∈ V ,
if G has a negativeweight cycle somewhere, then the BellmanFord algorithm...
View
Full
Document
 Fall '11
 ErikDemaine

Click to edit the document details