Data Structures in Java Lecture 19: Applications of DFS 11/30/2015 - - PowerPoint PPT Presentation

data structures in java
SMART_READER_LITE
LIVE PREVIEW

Data Structures in Java Lecture 19: Applications of DFS 11/30/2015 - - PowerPoint PPT Presentation

Data Structures in Java Lecture 19: Applications of DFS 11/30/2015 Daniel Bauer 1 Contents Applications of DFS Euler Circuits Biconnectivity in Undirected Graphs. Finding Strongly Connected Components for Directed Graphs. 2


slide-1
SLIDE 1

Data Structures in Java

Lecture 19: Applications of DFS

11/30/2015 Daniel Bauer

1

slide-2
SLIDE 2

Contents

  • Applications of DFS
  • Euler Circuits
  • Biconnectivity in Undirected Graphs.
  • Finding Strongly Connected Components for

Directed Graphs.

2

slide-3
SLIDE 3

Contents

  • Applications of DFS
  • Euler Circuits
  • Biconnectivity in Undirected Graphs.
  • Finding Strongly Connected Components for

Directed Graphs.

3

slide-4
SLIDE 4

Draw this Figure

Without lifting your pen off the paper.

4

slide-5
SLIDE 5

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

5

slide-6
SLIDE 6

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

6

slide-7
SLIDE 7

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

7

slide-8
SLIDE 8

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

8

slide-9
SLIDE 9

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

9

slide-10
SLIDE 10

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

10

slide-11
SLIDE 11

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

11

slide-12
SLIDE 12

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

12

slide-13
SLIDE 13

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once.

13

slide-14
SLIDE 14

Euler Paths

  • An Euler Path is a path through an undirected

graph that visits every edge exactly once. This graph does not have an Euler Path.

14

slide-15
SLIDE 15

Euler Circuit

This graph does NOT have an Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

15

slide-16
SLIDE 16

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

16

slide-17
SLIDE 17

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

17

slide-18
SLIDE 18

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

18

slide-19
SLIDE 19

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

19

slide-20
SLIDE 20

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

20

slide-21
SLIDE 21

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

21

slide-22
SLIDE 22

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

22

slide-23
SLIDE 23

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

23

slide-24
SLIDE 24

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

24

slide-25
SLIDE 25

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

25

slide-26
SLIDE 26

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node.

26

slide-27
SLIDE 27

Euler Circuit

  • An Euler Circuit is an Euler path that begins and

ends at the same node. This graph does not have an Euler Path.

27

slide-28
SLIDE 28

Necessary Condition for Euler Circuits

  • Observation:
  • Once we enter v, we need another edge to leave it.
  • If v has an odd number of edges, the last time we enter v,


we will be stuck! 3

28

slide-29
SLIDE 29

Necessary Condition for Euler Circuits

  • Observation:
  • Once we enter v, we need another edge to leave it.
  • If v has an odd number of edges, the last time we enter v,


we will be stuck! 2

29

slide-30
SLIDE 30

Necessary Condition for Euler Circuits

  • Observation:
  • Once we enter v, we need another edge to leave it.
  • If v has an odd number of edges, the last time we enter v,


we will be stuck! 1

30

slide-31
SLIDE 31

Necessary Condition for Euler Circuits

  • Observation:
  • Once we enter v, we need another edge to leave it.
  • If v has an odd number of edges, the last time we enter v,


we will be stuck!

  • For an Euler Circuit to exist in a graph, all vertices 


need to have even degree (even number of edges).

31

slide-32
SLIDE 32

Necessary Condition for Euler Paths

3

  • For an Euler Path to exist in a graph, exactly 0 or 2

vertices must have odd degree.

  • Start with one of the odd vertices.
  • End in the other one.

3

32

slide-33
SLIDE 33

Necessary Condition for Euler Paths

3

  • For an Euler Path to exist in a graph, exactly 0 or 2

vertices must have odd degree.

  • Start with one of the odd vertices.
  • End in the other one.

3

33

slide-34
SLIDE 34

Conditions for Euler Paths and Circuits

  • For an Euler Circuit to exist in a graph, all vertices 


need to have even degree (even number of edges).

  • For an Euler Path to exist in a graph, exactly 0 or 2

vertices need to have odd degree.

  • These conditions are also sufficient! 


(i.e. every graph that contains only vertices of even degree has an Euler circuit). (Hierholzer, 1873 )

34

slide-35
SLIDE 35

Seven Bridges of Königsberg

Leonhard Euler, 1735 Source: Wikipedia The city of Königsberg in Prussia (now Kaliningrad, Russia) was set on both sides of the Pregel River, and included two large islands which were connected to each other and the mainland by seven bridges. Euler’s Problem:
 Find a walk through the city that crosses every bridge 
 exactly once!

35

slide-36
SLIDE 36

Seven Bridges of Königsberg

Leonhard Euler, 1735

36

slide-37
SLIDE 37

Seven Bridges of Königsberg

Leonhard Euler, 1735

3 5 3 3

There is no Euler Path in this graph.

37

slide-38
SLIDE 38

Finding Euler Circuits

  • Start with any vertex s. First, using DFS find any circuit starting

and ending in s. Mark all edges on the circuit as visited.

  • Because all vertices have even degree, we are guaranteed

to not get stuck before we arrive at s again.

  • While there are still edges in the graph that are not market

visited:

  • Find the first vertex v on the circuit that has unvisited

edges.

  • Find a circuit starting in v and splice this path into the first

circuit

38

slide-39
SLIDE 39

Finding Euler Circuits

8 5 6 9

10

7 2 4

1

3

4 2 2 2 2 4 4 4 4 4

39

slide-40
SLIDE 40

Finding Euler Circuits

8 5 6 9

10

7 2 4

1

3

3 1 2 2 2 4 4 4 4 4

40

slide-41
SLIDE 41

Finding Euler Circuits

8 5 6 9

10

7 2 4

1

3

2 1 2 2 2 4 4 3 4 4

41

slide-42
SLIDE 42

Finding Euler Circuits

8 5 6 9

10

7 2 4

1

3

2 1 2 2 2 4 4 2 3 4

42

slide-43
SLIDE 43

Finding Euler Circuits

8 5 6 9

10

7 2 4

1

3

2 1 2 2 2 4 4 2 2 3

43

slide-44
SLIDE 44

Finding Euler Circuits

8 5 6 9

10

7 2 4

1

3

2 2 2 2 4 4 2 2 2

1 2 4 6 5 1

44

slide-45
SLIDE 45

1

Finding Euler Circuits

8 5 6 9

10

7

2

4 3

2 2 2 2 4 4 2 2 2

1 2 4 6 5 1

45

slide-46
SLIDE 46

1

Finding Euler Circuits

8 5 6 9

10

7

2

4 3

2 2 2 2 2 2

1 2 4 6 5 1 2 7 6 10 3 2

46

slide-47
SLIDE 47

1

Finding Euler Circuits

8 5 6 9

10

7

2

4 3

2 2 2 2 2 2

2 7 6 10 3 2 1 4 6 5 1

47

slide-48
SLIDE 48

1

Finding Euler Circuits

8 5 6 9

10

7

4 3

1 2 7 6 10 3 2 4 6 5 1

2

7 4 5 8 9 10 7

48

slide-49
SLIDE 49

1

Finding Euler Circuits

8 5 6 9

10

7

4 3 2

7 4 5 8 9 10 7 1 2 6 10 3 2 4 6 5 1

49

slide-50
SLIDE 50

Hamiltonian Cycle

  • A Hamiltonian Path is a path through an undirected

graph that visits every vertex exactly once (except that the first and last vertex may be the same).

  • A Hamiltonian Cycle is a Hamiltonian Path that

starts and ends in the same node. No hamiltonian path.

50

slide-51
SLIDE 51

Hamiltonian Cycle

  • We can check if a graph contains an Euler Cycle in

linear time.

  • Surprisingly, checking if a graph contains a

Hamiltonian Path/Cycle is much harder!

  • No polynomial time solution (i.e. O(Nk) ) is known.

No hamiltonian path.

51

slide-52
SLIDE 52

Contents

  • Applications of DFS
  • Euler Circuits
  • Biconnectivity in Undirected Graphs.
  • Finding Strongly Connected Components for

Directed Graphs.

52

slide-53
SLIDE 53
  • An undirected graph is connected if there is a


path from every vertex to every other vertex.

Connectivity

unconnected graph

  • Test for connectivity: See if DFS can reach all vertices.

53

slide-54
SLIDE 54

Biconnectivity

  • A graph is biconnected if there is no single vertex

v, such that removing v will disconnect the remaining graph.

A B C D E A B C D F E G

biconnected not biconnected

54

slide-55
SLIDE 55

Biconnectivity

  • A graph is biconnected if there is no single vertex

v, such that removing v will disconnect the remaining graph.

A B C D E A B F E G

biconnected not biconnected

D

55

slide-56
SLIDE 56

Biconnectivity

  • A graph is biconnected if there is no single vertex

v, such that removing v will disconnect the remaining graph.

A B C D E A B C D F E G

biconnected not biconnected

56

slide-57
SLIDE 57

Biconnectivity

  • A graph is biconnected if there is no single vertex

v, such that removing v will disconnect the remaining graph.

A B C D E A B F E G

biconnected not biconnected

C

57

slide-58
SLIDE 58

Biconnectivity

  • A graph is biconnected if there is no single vertex

v, such that removing v will disconnect the remaining graph.

A B C D E A B

C D

F E G

biconnected not biconnected C and D are articulation points.

58

slide-59
SLIDE 59

Testing for Biconnectivity

  • A graph G is biconnected if:
  • G is connected.
  • G does not contain any articulation points.

|V|·O(|V|+|E|) = O(|V|2 + |V|·|E|)

  • Naive approach:
  • Remove each vertex. Test if the resulting graph is still

connected.

59

slide-60
SLIDE 60

Depth First Spanning Tree

A B C D E

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.
  • Add a back edge for every skipped edge.

60

slide-61
SLIDE 61

Depth First Spanning Tree

A

B C D E A

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.

61

slide-62
SLIDE 62

Depth First Spanning Tree

A B

C D E A B

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.

62

slide-63
SLIDE 63

Depth First Spanning Tree

A B C

D E A B C

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.

63

slide-64
SLIDE 64

Depth First Spanning Tree

A B C D

E A B C D

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.

64

slide-65
SLIDE 65

Depth First Spanning Tree

A B C D

E A B C D

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.
  • Add a back edge for every skipped edge.

65

slide-66
SLIDE 66

Depth First Spanning Tree

A B C D

E A B C D

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.
  • Add a back edge for every skipped edge.

66

slide-67
SLIDE 67

Depth First Spanning Tree

A B C D E

A B C D E

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.
  • Add a back edge for every skipped edge.

67

slide-68
SLIDE 68

Depth First Spanning Tree

A B C D E

A B C D E

  • The steps taken by DFS can be illustrated as a (directed)

spanning tree.

  • Add a tree edge for every graph edge taken by DFS.
  • Add a back edge for every skipped edge.

68

slide-69
SLIDE 69

Identifying Articulation Points (1)

A B C D E

  • If the root of the DFS spanning tree has two outgoing


tree edges, the root is an articulation point.

A B C D F E G F G

C is an articulation point.

69

slide-70
SLIDE 70

Identifying Articulation Points (1)

A B D E

  • If the root of the DFS spanning tree has two outgoing


tree edges, the root is an articulation point.

A B C D F E G F C G

  • Depends on which vertex we start DFS from.

A is not an articulation point.

70

slide-71
SLIDE 71

Identifying Articulation Points (2)

A B

D E

  • Any non-root vertex v is an articulation point iff
  • v has a child w such that there is no 


back-edge from the subtree below w 
 to any ancestor of v.

A B C

D F E

G

F

C G

C is an articulation point because

  • f G.

71

slide-72
SLIDE 72

Identifying Articulation Points (2)

A B D E

  • Any non-root vertex v is an articulation point iff
  • v has a child w such that there is no 


back-edge from the subtree below w 
 to any ancestor of v.

A B C D F E

G

F C

G

D is an articulation point because

  • f E.

72

slide-73
SLIDE 73

Preorder Numbers

  • Assign numbers to each vertex in the order in which they


are visited by DFS.

  • For every tree edge (u,v): Num(u) < Num(v)
  • For every back edge (u,v): Num(u) > Num(v)

v Num(v) A 1 B 2 C 3 D 4 E 5 F 6 G 7

A B D E F C G

1 2 3 4 5 6 7

73

slide-74
SLIDE 74

Low numbers

  • For each vertex, find the lowest numbered vertex that is 


reachable by following a path that contains 
 at most one back edge.

v Num(v) Low(v) A 1 1 B 2 C 3 D 4 E 5 F 6 G 7

A B D E F C G

1 2 3 4 5 6 7

74

slide-75
SLIDE 75

Low numbers

  • For each vertex, find the lowest numbered vertex that is 


reachable by following a path that contains 
 at most one back edge.

v Num(v) Low(v) A 1 1 B 2 C 3 D 4 E 5 F 6 G 7

A B D E F C G

1 1 1 1 2 3 4 5 6 7

75

slide-76
SLIDE 76

Low numbers

  • For each vertex, find the lowest numbered vertex that is 


reachable by following a path that contains 
 at most one back edge.

v Num(v) Low(v) A 1 1 B 2 C 3 D 4 E 5 F 6 G 7

A B D E F C G

1 1 1 4 4 7 1 2 3 4 5 6 7

76

slide-77
SLIDE 77

Identifying Articulation Points

v Num(v) Low(v) A 1 1 B 2 C 3 D 4 E 5 F 6 G 7

A B D E F C G

1 1 1 4 4 7 1 2 3 4 5 6 7

  • Any non-root vertex v is an articulation point iff
  • v has a child w such that there is no 


back-edge from the subtree below w 
 to any ancestor of v.

77

slide-78
SLIDE 78

Identifying Articulation Points

v Num(v) Low(v) A 1 1 B 2 C 3 D 4 E 5 F 6 G 7

A B

D E

F

C G

1 1 1 4 4 7 1 2 3 4 5 6 7

  • Any non-root vertex v is an articulation point iff
  • v has a child w such that Low(w) ≥ Num(v)

78

slide-79
SLIDE 79

Computing Low Numbers Recursively

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

79

slide-80
SLIDE 80

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1

Computing Low Numbers Recursively

80

slide-81
SLIDE 81

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2

Computing Low Numbers Recursively

81

slide-82
SLIDE 82

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 3

Computing Low Numbers Recursively

82

slide-83
SLIDE 83

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 3 1 7

Computing Low Numbers Recursively

83

slide-84
SLIDE 84

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 3 1 5 7

Computing Low Numbers Recursively

84

slide-85
SLIDE 85

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 3 1 5 4 7

Computing Low Numbers Recursively

85

slide-86
SLIDE 86

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 3 1 4 4 7

Computing Low Numbers Recursively

86

slide-87
SLIDE 87

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 3 1 4 4 7

Computing Low Numbers Recursively

87

slide-88
SLIDE 88

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 2 1 1 4 4 7

Computing Low Numbers Recursively

88

slide-89
SLIDE 89

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 1 1 1 4 4 7

Computing Low Numbers Recursively

89

slide-90
SLIDE 90

Computing Low Numbers

A B D E F C G

1 2 3 4 5 6 7

Low(v) = Num(v) for all back edges (v,u) { if ( Num(u) < Low(v) ) Low(v) = Num(u); } for all tree edges (v,u) { compute_low(u); if ( Low(u) < Low(v) )
 Low(v) = Low(u); } compute_low(v) { }

1 1 1 1 4 4 7

Time to compute low numbers: O(|V|+|E|) Time to compute preorder numbers: O(|V| +|E|) Time to check for articulation points: O(|V|+|E|) Total: O(|V|+|E|)

90

slide-91
SLIDE 91

Contents

  • Applications of DFS
  • Euler Circuits
  • Biconnectivity in Undirected Graphs.
  • Finding Strongly Connected Components for

Directed Graphs.

91

slide-92
SLIDE 92
  • A directed graph is weakly connected if there is

an undirected path from every vertex to every other vertex.

Connectivity in Directed Graphs

weakly connected graph

92

slide-93
SLIDE 93
  • A directed graph is strongly connected if there is

a path from every vertex to every other vertex.

Strongly Connected Graphs

v

Weakly connected, but not strongly connected (no other vertex can be reached from v).

93

slide-94
SLIDE 94
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

94

slide-95
SLIDE 95
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

95

slide-96
SLIDE 96
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

96

slide-97
SLIDE 97
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

97

slide-98
SLIDE 98
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

98

slide-99
SLIDE 99
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

99

slide-100
SLIDE 100
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

100

slide-101
SLIDE 101
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

101

slide-102
SLIDE 102
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

102

slide-103
SLIDE 103
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

103

slide-104
SLIDE 104
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

104

slide-105
SLIDE 105
  • Run DFS to see if all vertices are reachable from

some start node s.

Testing if a Graph is Strongly Connected

s

  • Reverse direction of edges and run DFS again.

105

slide-106
SLIDE 106
  • Goal: Partition the graph into subgraphs such that

each partition is strongly connected.

Strongly Connected Components

106

slide-107
SLIDE 107
  • Goal: Partition the graph into subgraphs such that

each partition is strongly connected.

Strongly Connected Components

A D E B C F G H J I

107

slide-108
SLIDE 108
  • Goal: Partition the graph into subgraphs such that

each partition is strongly connected.

Strongly Connected Components

A D E B C F

G H J I

108

slide-109
SLIDE 109
  • Goal: Partition the graph into subgraphs such that

each partition is strongly connected.

Strongly Connected Components

A D E B C F G H J I

109

slide-110
SLIDE 110
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A

D B C F G H J I E

110

slide-111
SLIDE 111
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D

B C F G H J I

E

E

111

slide-112
SLIDE 112
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D

B C F G H J I

E

E D

112

slide-113
SLIDE 113
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B

C F G H J I

E

E D A

113

slide-114
SLIDE 114
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B C

F G H J I

E

E D A C

114

slide-115
SLIDE 115
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B C F

G H J I

E

E D A C B F

115

slide-116
SLIDE 116
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B C F

G

H

J I

E

E D A C B F

116

slide-117
SLIDE 117
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B C F

G

H J I E

E D A C B F J I

117

slide-118
SLIDE 118
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B C F

G

H J I E

E D A C B F J I H

118

slide-119
SLIDE 119
  • Run DFS and push all fully expanded nodes on a
  • stack. If we get stuck, restart search at an arbitrary

unvisited node.

Finding Strongly Connected Components

A D B C F G H J I E

E D A C B F J I H G

119

slide-120
SLIDE 120
  • Reverse the edge directions.

Finding Strongly Connected Components

A D E B C F G H J I

E D A C B F J I H G

120

slide-121
SLIDE 121
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A D E B C F G H J I

E D A C B F J I H G

121

slide-122
SLIDE 122
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A D E B C F

G

H J I

E D A C B F J I H

122

slide-123
SLIDE 123
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A D E B C F

G

H J I

E D A C B F J I H

123

slide-124
SLIDE 124
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A D E B C F

G H J I

E D A C B F J I

124

slide-125
SLIDE 125
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A D E B C F

G H J I

E D A C B F

125

slide-126
SLIDE 126
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A

D E

B C F G H J I

E D A C B

126

slide-127
SLIDE 127
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A

D E

B C F G H J I

E D

127

slide-128
SLIDE 128
  • Pop the top vertex off the stack and run DFS. The set of visited

nodes are a strong component. Remove this component from the graph and stack.

  • Continue until stack is empty.

Finding Strongly Connected Components

A D

E

B C F G H J I

E

128