quiz2

Include the name of the algorithm 3 topological sort

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: 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 in-degree 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 single-source shortest paths on a large graph. Lazy writes a subroutine that, given G = (V, E ), a source vertex s, and a non-negative edge-weight function w : E → R, outputs a mapping d : V → R such that d[v ] is supposed to be the weight δ (s, v ) of the shortest-weight 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

Ask a homework question - tutors are online