This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 101 Figure 3.8 A directed acyclic graph with one source, two sinks, and four possible lineariza tions. A B C D E F What types of dags can be linearized? Simple: All of them . And once again depthfirst search tells us exactly how to do it: simply perform tasks in decreasing order of their post numbers. After all, the only edges ( u, v ) in a graph for which post ( u ) < post ( v ) are back edges (recall the table of edge types on page 100)—and we have seen that a dag cannot have back edges. Therefore: Property In a dag, every edge leads to a vertex with a lower post number. This gives us a lineartime algorithm for ordering the nodes of a dag. And, together with our earlier observations, it tells us that three rather differentsounding properties—acyclicity, linearizability, and the absence of back edges during a depthfirst search—are in fact one and the same thing. Since a dag is linearized by decreasing post numbers, the vertex with the smallest post number comes last in this linearization, and it must be a sink —no outgoing edges. Symmet rically, the one with the highest post is a source , a node with no incoming edges. Property Every dag has at least one source and at least one sink. The guaranteed existence of a source suggests an alternative approach to linearization: Find a source, output it, and delete it from the graph. Repeat until the graph is empty. Can you see why this generates a valid linearization for any dag? What happens if the graph has cycles? And, how can this algorithm be implemented in linear time? (Exercise 3.14.) 3.4 Strongly connected components 3.4.1 Defining connectivity for directed graphs Connectivity in undirected graphs is pretty straightforward: a graph that is not connected can be decomposed in a natural and obvious manner into several connected components (Fig 102 Algorithms Figure 3.9 (a) A directed graph and its strongly connected components. (b) The metagraph. (a) A D E C F B H G K L J I (b) A B,E C,F D J,K,L G,H,I ure 3.6 is a case in point). As we saw in Section 3.2.3, depthfirst search does this handily, with each restart marking a new connected component. In directed graphs, connectivity is more subtle. In some primitive sense, the directed graph of Figure 3.9(a) is “connected”—it can’t be “pulled apart,” so to speak, without breaking edges. But this notion is hardly interesting or informative. The graph cannot be considered connected, because for instance there is no path from G to B or from F to A . The right way to define connectivity for directed graphs is this: Two nodes u and v of a directed graph are connected if there is a path from u to v and a path from v to u ....
View
Full
Document
This document was uploaded on 08/10/2011.
 Spring '11
 Algorithms

Click to edit the document details