# G t f 2 points in a weighted undirected tree g v e

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

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 single-source 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 shortest-path 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 negative-weight edges. (j) T F [2 points] Given a weighted directed graph G = (V, E, w) and a source s ∈ V , if G has a negative-weight cycle somewhere, then the Bellman-Ford algorithm...
View Full Document

Ask a homework question - tutors are online