Download - Directed Acyclic Graph
1
Directed Acyclic Graph
• DAG – directed graph with no directed cycles
2
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
3
Topological Sort
• Linear ordering of the vertices of G, such that if (u,v)E, then u appears smewhere before v.
4
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Socks Underwear Pants Shoes Watch Shirt Belt Tie Jacket
5
Topological Sort
Topological-Sort (G)1. call DFS(G) to compute finishing times f [v] for all v V2. as each vertex is finished, insert it onto the front of a linked list3. return the linked list of vertices
Time: (|V|+|E|).
6
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
1 |Undiscovered
Active
Finished
Unfinished
7
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
1 |
2 |
Undiscovered
Active
Finished
Unfinished
8
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
1 |
2 |
3 |
Undiscovered
Active
Finished
Unfinished
9
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Jacket
1 |
2 |
3 | 4
Undiscovered
Active
Finished
Unfinished
10
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Tie Jacket
1 |
2 | 5
3 | 4
Undiscovered
Active
Finished
Unfinished
11
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Tie Jacket
6 |
1 |
2 | 5
3 | 4
Undiscovered
Active
Finished
Unfinished
12
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Belt Tie Jacket
6 | 7
1 |
2 | 5
3 | 4
Undiscovered
Active
Finished
Unfinished
13
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Shirt Belt Tie Jacket
6 | 7
1 | 8
2 | 5
3 | 4
Undiscovered
Active
Finished
Unfinished
14
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Shirt Belt Tie Jacket
6 | 7
1 | 8
2 | 5
3 | 4
9 |
Undiscovered
Active
Finished
Unfinished
15
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Watch Shirt Belt Tie Jacket
6 | 7
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
16
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Watch Shirt Belt Tie Jacket
11 |
6 | 7
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
17
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Watch Shirt Belt Tie Jacket
11 |
12 |
6 | 7
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
18
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Watch Shirt Belt Tie Jacket
11 |
12 |
6 | 7
13 |
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
19
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Shoes Watch Shirt Belt Tie Jacket
11 |
12 |
6 | 7
13 |14
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
20
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Pants Shoes Watch Shirt Belt Tie Jacket
11 |
12 |15
6 | 7
13 |14
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
21
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Underwear Pants Shoes Watch Shirt Belt Tie Jacket
11 | 16
12 |15
6 | 7
13 |14
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
22
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Underwear Pants Shoes Watch Shirt Belt Tie Jacket
11 | 16
12 |15
6 | 7
13 |14
17 |
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
23
Getting Dressed
Underwear Socks
ShoesPants
Belt
Shirt
Watch
Tie
Jacket
Socks Underwear Pants Shoes Watch Shirt Belt Tie Jacket
11 | 16
12 |15
6 | 7
13 |14
17 | 18
1 | 8
2 | 5
3 | 4
9 |10
Undiscovered
Active
Finished
Unfinished
24
Strongly-Connected
• Graph G is strongly connected if, for every u and v in V, there is some path from u to v and some path from v to u.
Strongly Connected
Not Strongly Connected
25
• A strongly connected component (SCC) of G is a maximal set of vertices C V such that for all u, v C, both u v and v u exist.
Strongly Connected Components
26
• GSCC=(VSCC, ESCC): one vertex for each component– (u, v) ESCC if there exists at least one directed
edge from the corresponding components
Graph of Strongly Connected Components
27
• GSCC has a topological ordering
Graph of Strongly Connected Components
28
1 |12 8 |11 13|16
14|155 | 63 | 4
2 | 7 9 |10
sourcevertex
d f
Tree edges Back edges Forward edges Cross edges
Kinds of Edges
B F
C
C
C
C
C
C