{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_05

# lecture_05 - Directed graphs Paths cycles strongly...

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

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

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

View Full Document
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”.
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

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

View Full Document
Example DFS(“e”) would visit “e”, “b” and “a”. e e 4 a c b d f a b
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).

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

View Full Document
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
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 ?

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

View Full Document
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 ?
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

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

View Full Document
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?
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online