Algorithms_Part6 - S Dasgupta C.H Papadimitriou and U.V Vazirani 101 Figure 3.8 A directed acyclic graph with one source two sinks and four

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 depth-first 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 linear-time algorithm for ordering the nodes of a dag. And, together with our earlier observations, it tells us that three rather different-sounding properties—acyclicity, linearizability, and the absence of back edges during a depth-first 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 meta-graph. (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, depth-first 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.

Page1 / 20

Algorithms_Part6 - S Dasgupta C.H Papadimitriou and U.V Vazirani 101 Figure 3.8 A directed acyclic graph with one source two sinks and four

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online