lecture_05 - Directed graphs Paths, cycles, strongly...

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

View Full Document Right Arrow Icon
Directed graphs Paths, cycles, strongly connected, sink/source of acyclic graphs, strongly connected components DasGupta et al. 3.3, 3.4 Cormen et al.: 22.4, 22.5
Background image of page 1

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

View Full DocumentRight Arrow Icon
Directed graphs (Digraphs) Each edge has an orientation. We distinguish an edge from u to v (denoted (u,v) ) from an edge from v to u (denoted (v,u) ) . A path from a vertex u to a vertex v does not imply a path from v to u. .g., there is a path 2 a c b d e f E.g., there is a path from “c” to “e”. But there is no path from “e” to “c”.
Background image of page 2
Connectivity problem Given a directed graph G=(V,E) and a vertex s , 1. find all vertices w such that there is a path from s to w ; 2. find all vertices w which have a path to s . Problem 1 can be solved using depth start search in O(n+m) 3 time, where n=|V| and m =|E|. DFS (u) 1. Visited[u] = true; 2. For each vertex v in the adjacent list of u, if Visited[ v ] = false then DFS( v ) (u,v) in E
Background image of page 3

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

View Full DocumentRight Arrow Icon
Example DFS(“e”) would visit “e”, “b” and “a”. e e 4 a c b d f a b
Background image of page 4
Connectivity problem Given a directed graph G=(V, E) and a vertex s, 1. find all vertices w such that s has a path to w; 2. Find all vertices w which have a path to s. Problem 2 can be solved via a reduction to problem 1. 5 Definition . The reverse graph G R = same vertex set as G, with edges reversed. Lemma . G contains a path from u to v if and only if G R contains a path from v to u. To solve Problem 2, s construct G R ; s find in G R all vertices w to which s has a path (by DFS).
Background image of page 5

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

View Full DocumentRight Arrow Icon
Reverse graph e e DFS( G R ,“e”) would visit “a”, “b”, “c”, “d”, “f” and “e”. 6 a c d f b a c d f b G R
Background image of page 6
Strongly connected Two vertices u and v are said to be strongly connected if there is a path from u to v, as well as a path from v to u. A directed graph is strongly connected if every two vertices are strongly connected. Checking whether a graph is strongly connected 7 s O(n(n+m)) time, trivial ? s O(n+m) time, possible ?
Background image of page 7

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

View Full DocumentRight Arrow Icon
Strongly connected A directed graph is strongly connected if every two vertices are strongly connected. A simple O(n+m)-time algorithm: 8 Pick any vertex s , check if s can reach all vertexes and all vertexes can reach s . If yes, we conclude that G is strongly connected. Too simple to be correct ?
Background image of page 8
Correctness Pick any node s, check if s can reach every node and every node can reach s. If yes, we conclude that G is strongly connected. Lemma . For any vertices u , v and s , if s and u are strongly 9 connected, and s and v are strongly connected, then u and v are strongly connected . s u v
Background image of page 9

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

View Full DocumentRight Arrow Icon
Cycles Problem: Given a digraph G, determines whether G contains a cycle. O(n(n+m)) time, trivial ? 10 O(n+m) time? DFS and back edges?
Background image of page 10
DFS: classification of non-tree edges b a c e f d b a e c d root 11 DFS Tree – root, descendants, and ancestors. s
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2010 for the course CS 1234 taught by Professor Chan during the Spring '10 term at University of the Bío-Bío.

Page1 / 42

lecture_05 - Directed graphs Paths, cycles, strongly...

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

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