660 likes | 755 Views
CSC 213 – Large Scale Programming. Lecture 33: Directed Graph Connectivity. Today’s Goals. Examine new properties of DirectedGraph s What reaching & reachable mean for a Graph How humans go about computing these properties Algorithms for computers to compute these
E N D
CSC 213 – Large Scale Programming Lecture 33:Directed Graph Connectivity
Today’s Goals • Examine new properties of DirectedGraphs • What reaching & reachablemean for a Graph • How humans go about computing these properties • Algorithms for computers to compute these • Examine what meant by DAG and why you care • Simple ways to develop schedules will be examined • How can algorithm tell when a schedule impossible
Directed Graph • Only directed edges • Replace undirected edge with 2 directed edges • Relationships go in only one direction • One-way streets • Flights • Scheduling E D C B A
Directed Graph • Only directed edges • Replace undirected edge with 2 directed edges • Relationships go in only one direction • One-way streets • Flights • Scheduling • Talking to your ex
Directed Graph Properties e • Each edge goes one-way • (a,b)connectsatob • (a,b) does not connectb to a • Can discuss in-edges & out-edges • (a,b) is out-edge for a • (a,b) is in-edge for b • Adjacency-based Graph classes can change • Use 2 Sequences for adjacency-list vertices • Define source & target dimension in adjacency-matrix incidentEdges returns both in-edges & out-edges d c b a
Reachability • e,a,dreachable from c e d c f a b
Reachability • e,a,dreachable from c • creaches e e d c f a b
Reachability • e,a,dreachable from c • creaches e • c reaches e & eincident upond,a e d c f a b
Reachability • e,a,dreachable from c • creaches e • c reaches e & eis incident upond,a • d,aout-edges to c only e d c f a b
Reachability • a,c,d,e,freachablefromb e d c f a b
Reachability • a,c,d,e,freachablefromb • Path exists from b to every vertex e d c f a b
Reachability • a,c,d,e,freachablefromb • Path exists from b to every vertex • Actually have multiple paths to most vertices e d c f a b
Transitive Closure of G • Transitive closure ofGusually written as G* d e b c a G G*
Transitive Closure of G • Transitive closure ofGusually written as G* • Identical vertex sets in G & G* • G & G* have different edge sets, however d e d e b b c c a a G G*
Transitive Closure of G • Transitive closure ofGusually written as G* • Identical vertex sets in G & G* • G & G* have different edge sets, however • Edge in G*if targetreachable from sourceinG d e d e b b c c a a G G*
Transitive Closure of G • Transitive closure ofGusually written as G* • Identical vertex sets in G & G* • G & G* have different edge sets, however • Edge in G*if targetreachable from sourceinG d e d e b b c c a a G G*
Transitive Closure of G • Transitive closure ofGusually written as G* • Identical vertex sets in G & G* • G & G* have different edge sets, however • Edge in G*if targetreachable from sourceinG d e d e b b c c a a G G*
Transitive Closure of G • Transitive closure ofGusually written as G* • Identical vertex sets in G & G* • G & G* have different edge sets, however • Edge in G*if targetreachable from sourceinG d e d e b b c c a a G G*
Transitive Closure of G • Transitive closure ofGusually written as G* • Identical vertex sets in G & G* • G & G* have different edge sets, however • Edge in G*if targetreachable from sourceinG d e d e b b c c a a G G*
Computing Transitive Closure • Use dynamic programming to compute this • This solution known as Floyd-Warshall Algorithm • But how fast is it?
Floyd-Warshall’s Algorithm • Number G’s vertices from 1 to n • Algorithm will compute n directed graphs • Set G0=G to initialize this algorithm • Graph of transitive closure is end result (Gn = G*) • All ndirected graphs have same vertices • Gk contains all edges in Gk-1 (and Gk-2, Gk-3 ,…, G0) • Gk also has edge (vi,vj)if edges (vi,vk) & (vk,vj)in Gk-1 • Takes O(n3) time with adjacency matrix • Better to use “brute force” if few edges exist
Floyd-Warshall’s Algorithm • Number G’s vertices from 1 to n • Algorithm willcompute n directed graphs • Set G0=G to initialize this algorithm • Graph of transitive closure is end result (Gn = G*) • All n directed graphs have same vertices • Gk contains all edges in Gk-1(and Gk-2, Gk-3 ,…, G0) • Gk also has edge (vi,vj)if edges (vi,vk) & (vk,vj)in Gk-1 • Takes O(n3) time with adjacency matrix • Better to use “brute force” if few edges exist
Floyd-WarshallExample – G0 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G1 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G1 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G1 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G1 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G1 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G2 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G2 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G3 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G3 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G3 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G3 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G3 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G4 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G4 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G4 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G4 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G4 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G4 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G5 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G5 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G5 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G5 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G6 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G6 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G7 V7 V4 V6 V2 V3 V1 V5
Floyd-WarshallExample – G* V7 V4 V6 V2 V3 V1 V5
Directed Acyclic Graph • Often called a DAG • Number & sort vertices • Topological order found • Eachedge (vi,vj) has i < j • Finds valid schedules… • …or proves cannot exist! d e b G (is a DAG) c a 5 4 d e 1 A valid ordering of G b 3 c 2 a