Download presentation

Presentation is loading. Please wait.

Published byBaldric Simmons Modified about 1 year ago

1
CSC 213 – Large Scale Programming

2
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 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

3
Directed Graph Only directed edges Replace undirected edge with 2 directed edges Relationships go in only one direction One-way streets Flights Scheduling A C E B D

4
Directed Graph

5
Directed Graph Properties Each edge goes one-way (a,b) connects a to b does not connect (a,b) does not connect b 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 a c e b d

6
Reachability e, a, d reachable from c a c e b d f

7
Reachability e, a, d reachable from c c reaches e a c e b d f

8
Reachability e, a, d reachable from c c reaches e c reaches e & e incident upon d, a a c e b d f

9
Reachability e, a, d reachable from c c reaches e c reaches e & e is incident upon d, a d, a out-edges to c only a c e b d f

10
Reachability a, c, d, e, f reachable from b a c e b d f

11
Reachability a, c, d, e, f reachable from b Path exists from b to every vertex a c e b d f

12
Reachability a, c, d, e, f reachable from b Path exists from b to every vertex Actually have multiple paths to most vertices a c e b d f

13
Transitive Closure of G Transitive closure of G usually written as G* b a d c e GG*G*

14
Transitive Closure of G Transitive closure of G usually written as G* Identical vertex sets in G & G* G & G* have different edge sets, however b a d c e GG*G* b a d c e

15
Transitive Closure of G Transitive closure of G usually written as G* Identical vertex sets in G & G* G & G* have different edge sets, however Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

16
Transitive Closure of G Transitive closure of G usually written as G* Identical vertex sets in G & G* G & G* have different edge sets, however Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

17
Transitive Closure of G Transitive closure of G usually written as G* Identical vertex sets in G & G* G & G* have different edge sets, however Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

18
Transitive Closure of G Transitive closure of G usually written as G* Identical vertex sets in G & G* G & G* have different edge sets, however Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

19
Transitive Closure of G Transitive closure of G usually written as G* Identical vertex sets in G & G* G & G* have different edge sets, however Edge in G* if target reachable from source in G b a d c e GG*G* b a d c e

20
Computing Transitive Closure Use dynamic programming to compute this This solution known as Floyd-Warshall Algorithm But how fast is it?

21
Floyd-Warshall’s Algorithm Number G ’s vertices from 1 to n Algorithm will compute n directed graphs Set G 0 =G to initialize this algorithm Graph of transitive closure is end result ( G n = G* ) All n directed graphs have same vertices G k contains all edges in G k-1 (and G k-2, G k-3,…, G 0 ) G k also has edge ( v i, v j ) if edges ( v i, v k ) & ( v k, v j ) in G k-1 Takes O(n 3 ) time with adjacency matrix Better to use “brute force” if few edges exist

22
Floyd-Warshall’s Algorithm Number G ’s vertices from 1 to n Algorithm will compute n directed graphs Set G 0 =G to initialize this algorithm Graph of transitive closure is end result ( G n = G* ) All n directed graphs have same vertices G k contains all edges in G k-1 (and G k-2, G k-3,…, G 0 ) G k also has edge ( v i, v j ) if edges ( v i, v k ) & ( v k, v j ) in G k-1 Takes O(n 3 ) time with adjacency matrix Better to use “brute force” if few edges exist

23
Floyd-Warshall Example – G 0 V6V6 V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

24
V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

25
V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

26
V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

27
V6V6 V7V7 V5V5 V4V4 V3V3 V2V2

28
V6V6 V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

29
V6V6 V7V7 V5V5 V4V4 V1V1 V3V3

30
V6V6 V7V7 V5V5 V4V4 V1V1 V3V3

31
V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

32
V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

33
V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

34
V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

35
V6V6 V7V7 V5V5 V4V4 V1V1 V2V2

36
V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

37
V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

38
V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

39
V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

40
V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

41
V6V6 V7V7 V5V5 V1V1 V3V3 V2V2

42
V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

43
V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

44
V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

45
V6V6 V7V7 V4V4 V1V1 V3V3 V2V2

46
V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

47
V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

48
V6V6 V5V5 V4V4 V1V1 V3V3 V2V2

49
Floyd-Warshall Example – G * V6V6 V7V7 V5V5 V4V4 V1V1 V3V3 V2V2

50
DAG Directed Acyclic Graph Often called a DAG Number & sort vertices Topological order found Each edge ( v i, v j ) has i < j Finds valid schedules… …or proves cannot exist! b a d c e G (is a DAG) b a d c e A valid ordering of G

51
DAG Directed Acyclic Graph Often called a DAG Number & sort vertices Topological order found Each edge ( v i, v j ) has i < j Finds valid schedules… …or proves cannot exist! b a d c e G (is a DAG) b a d c e Another valid ordering of G

52
Topological Sorting Edges connect smaller to larger vertex numbers wake up study eat class study homework work study go to bed dream about classwork Professor’s expectation of student’s day

53
Topological Sort Algorithm Algorithm topologicalSort( Graph G) H // Make a copy of G m new Vertex[ G.numVertices() ] stack new … Stack () // Push onto stack any vertex in H with no outgoing edges n G.numVertices() while n ≥ 1 do v stack.pop() n n – 1 m[n] v foreach e in v.incidentEdges() ≠ 0 do w H.opposite(e, v) // Remove e from H if w has no outgoing edges then stack.push(w) return m

54
Topological Sorting Example

55

56

57

58

59

60

61

62

63

64

65

66
For Next Lecture Weekly assignment out & due tomorrow Programming assignment #3 plans due Friday Please do not wait to start working on these ideas For Wednesday, read & Find quickest way to get someplace, can it be done? How can we find the spanning tree that weighs least?

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google