This preview shows page 1. Sign up to view the full content.
Unformatted text preview: equal? (Include the name of the algorithm.) 3 Topological Sort Another way of performing topological sorting on a directed acyclic graph G = (V, E ) is to repeatedly ﬁnd a vertex of indegree 0 (no incoming edges), output it, and remove it and all of its outgoing edges from the graph. Explain how to implement this idea so that it runs in time O(V + E ). What happens to this algorithm if G has cycles? Handout 9: Quiz 2 Practice Problems 5 4 Shortest Paths Carrie Careful has hired Lazy Lazarus to help her compute singlesource shortest paths on a large graph. Lazy writes a subroutine that, given G = (V, E ), a source vertex s, and a nonnegative edgeweight function w : E → R, outputs a mapping d : V → R such that d[v ] is supposed to be the weight δ (s, v ) of the shortestweight path from s to v (or ∞ if no such s → v path exists) and also a function π : V → (V ∪ {N IL}) such that π [v ] is the penultimate vertex on one such shortest path (or NIL if v = s or v...
View Full
Document
 Spring '08
 ErikDemaine
 Algorithms

Click to edit the document details