articulation point, scc
TRANSCRIPT
-
8/12/2019 Articulation Point, Scc
1/33
-
8/12/2019 Articulation Point, Scc
2/33
Applications
Depth-first searchBiconnectivity
Euler circuitsStrongly-connected components
2
-
8/12/2019 Articulation Point, Scc
3/33
Depth-First Search
3
Recursively visit everyvertex in the graphConsiders every edge inthe graph
Assumes undirected edge(u,v) is in us and vsadjacency list
Visited flag preventsinfinite loopsRunning time O(|V|+|E|)
DFS () ;; graph G=(V,E)foreach v in V
if (! v.visited)then Visit (v)
Visit (vertex v)v.visited = trueforeach w adjacent to v
if (! w.visited)then Visit (w)
A
DB
C
E
-
8/12/2019 Articulation Point, Scc
4/33
DFS Applications
Undirected graphTest if graph is connectedRun DFS from any vertex andthen check if any vertices notvisited
Depth-first spanning tree Add edge (v,w) to spanningtree if w not yet visited(minimum spanning tree?)If graph not connected, thendepth-first spanning forest
4
A
DB
C
E
-
8/12/2019 Articulation Point, Scc
5/33
DFS Applications
Remembering the DFS traversal order is importantfor many applicationsLet the edges (v,w) added to the DF spanning treebe directed
Add a directed back edge (dashed) if w is already visited when considering edge (v,w), andv is already visited when considering reverse edge (w,v)
5
A
DB
C
E
A
DB
C
E
-
8/12/2019 Articulation Point, Scc
6/33
Biconnectivity
A connected, undirectedgraph is biconnected if thegraph is still connected afterremoving any one vertex
I.e., when a node fails, thereis always an alternative route
If a graph is not biconnected,
the disconnecting vertices arecalled articulation points
Critical points of interest in
many applications6
Biconnected? Articulation points?
-
8/12/2019 Articulation Point, Scc
7/33
DFS Applications: Finding Articulation Points
From any vertex v, perform DFS and number verticesas they are visitedNum(v) is the visit number
Let Low(v) = lowest-numbered vertex reachable fromv using 0 or more spanning tree edges and then atmost one back edge
Low(v) = minimum of Num(v)Lowest Num(w) among all back edges (v,w)Lowest Low(w) among all tree edges (v,w)
Can compute Num(v) and Low(v) in O(|E|+|V|) time7
-
8/12/2019 Articulation Point, Scc
8/33
DFS Applications: Finding Articulation Points (Example)
8
Original Graph
Depth-first treestarting at A withNum/Low values:
-
8/12/2019 Articulation Point, Scc
9/33
DFS Applications: Finding Articulation Points
Root is articulation point iff it has morethan one child
Any other vertex v is an articulationpoint iff v has some child w such thatLow(w) Num(v)
I.e., is there a child w of v that cannotreach a vertex visited before v?
If yes, then removing v will disconnect w(and v is an articulation point)9
-
8/12/2019 Articulation Point, Scc
10/33
DFS Applications: Finding Articulation Points (Example)
10
Original Graph
Depth-first treestarting at C withNum/Low values:
-
8/12/2019 Articulation Point, Scc
11/33
DFS Applications: Finding Articulation Points
High-level algorithmPerform pre-order traversal to compute NumPerform post-order traversal to compute Low
Perform another post-order traversal to detectarticulation points
Last two post-order traversals can becombinedIn fact, all three traversals can be combined
in one recursive algorithm11
-
8/12/2019 Articulation Point, Scc
12/33
Implementation
12
-
8/12/2019 Articulation Point, Scc
13/33
13
Check for rootomitted.
-
8/12/2019 Articulation Point, Scc
14/33
14
Check for rootomitted.
-
8/12/2019 Articulation Point, Scc
15/33
Euler Circuits
Puzzle challengeCan you draw a figure using a pen,drawing each line exactly once, withoutlifting the pen from the paper?
And, can you finish where you started?
15
-
8/12/2019 Articulation Point, Scc
16/33
Euler Circuits
Solved by Leonhard Eulerin 1736 using a graphapproach (DFS)
Also called an Euler pathor Euler tour Marked the beginning of
graph theory
16
-
8/12/2019 Articulation Point, Scc
17/33
Euler Circuit Problem
Assign a vertex to each intersection in thedrawing Add an undirected edge for each linesegment in the drawingFind a path in the graph that traverses eachedge exactly once, and stops where it started
17
-
8/12/2019 Articulation Point, Scc
18/33
Euler Circuit Problem
Necessary and sufficient conditionsGraph must be connectedEach vertex must have an even degree
Graph with two odd-degree vertices can havean Euler tour (not circuit)
Any other graph has no Euler tour or circuit
18
-
8/12/2019 Articulation Point, Scc
19/33
Euler Circuit Problem
AlgorithmPerform DFS from some vertex v until youreturn to v along path pIf some part of graph not included,perform DFS from first vertex v on p that
has an un-traversed edge (path p)Splice p into pContinue until all edges traversed
19
-
8/12/2019 Articulation Point, Scc
20/33
Euler Circuit Example
20
Start at vertex 5.
Suppose DFS visits 5, 4, 10, 5.
-
8/12/2019 Articulation Point, Scc
21/33
Euler Circuit Example (cont.)
21
Graph remaining after 5, 4, 10, 5:
Start at vertex 4.Suppose DFS visits 4, 1, 3, 7, 4, 11, 10, 7, 9, 3, 4.Splicing into previous path: 5, 4, 1, 3, 7, 4, 11, 10, 7, 9, 3, 4, 10, 5.
-
8/12/2019 Articulation Point, Scc
22/33
Euler Circuit Example (cont.)
22
Graph remaining after 5, 4, 1, 3, 7, 4, 11, 10, 7, 9, 3, 4, 10, 5:
Start at vertex 3.Suppose DFS visits 3, 2, 8, 9, 6, 3.Splicing into previous path: 5, 4, 1, 3, 2, 8, 9, 6, 3, 7, 4, 11, 10, 7, 9, 3, 4, 10, 5.
-
8/12/2019 Articulation Point, Scc
23/33
Euler Circuit Example (cont.)
23
Graph remaining after 5, 4, 1, 3, 2, 8, 9, 6, 3, 7, 4, 11, 10, 7, 9, 3, 4, 10, 5:
Start at vertex 9.Suppose DFS visits 9, 12, 10, 9.Splicing into previous path: 5, 4, 1, 3, 2, 8, 9, 12, 10, 9, 6, 3, 7, 4, 11, 10, 7, 9, 3, 4, 10, 5.No more un-traversed edges, so above path is an Euler circuit.
-
8/12/2019 Articulation Point, Scc
24/33
Euler Circuit Algorithm
Implementation detailsMaintain circuit as a linked list to supportO(1) splicingMaintain index on adjacency lists to avoidrepeated searches for un-traversed edges
AnalysisEach edge considered only onceRunning time is O(|E|+|V|)
24
-
8/12/2019 Articulation Point, Scc
25/33
DFS on Directed Graphs
Same algorithmGraph may beconnected, but notstrongly connectedStill want the DFspanning forest toretain information
about the search25
DFS () ;; graph G=(V,E)
foreach v in V if (! v.visited)then Visit (v)
Visit (vertex v)v.visited = trueforeach w adjacent to v
if (! w.visited)then Visit (w)
A
DB
C
E
-
8/12/2019 Articulation Point, Scc
26/33
DF Spanning Forest
Three types of edges in DF spanning forestBack edges linking a vertex to an ancestorForward edges linking a vertex to a descendant
Cross edges linking two unrelated vertices
26
A
DB
C
E
A
DB
C
E
Graph: DF Spanning Forest:
back
cross
-
8/12/2019 Articulation Point, Scc
27/33
DF Spanning Forest
27
Graph
DF Spanning Forest
back
back
cross
forward
(Note: DF Spanning Forests usuallydrawn with children and new treesadded from left to right.)
-
8/12/2019 Articulation Point, Scc
28/33
DFS on Directed Graphs
ApplicationsTest if directed graph is acyclic
Has no back edges
Topological sortReverse post-order traversal of DF spanningforest
28
-
8/12/2019 Articulation Point, Scc
29/33
Strongly-ConnectedComponents
A graph is strongly connected if every vertex can bereached from every other vertex
A strongly-connected component of a graph is asubgraph that is strongly connectedWould like to detect if a graph is strongly connectedWould like to identify strongly-connected componentsof a graphCan be used to identify weaknesses in a network General approach: Perform two DFSs
29
-
8/12/2019 Articulation Point, Scc
30/33
Strongly-ConnectedComponents
AlgorithmPerform DFS on graph GNumber vertices according to a post-order traversal ofthe DF spanning forest
Construct graph G r by reversing all edges in GPerform DFS on G r
Always start a new DFS (initial call to Visit) at thehighest-numbered vertex
Each tree in resulting DF spanning forest is astrongly-connected component
30
-
8/12/2019 Articulation Point, Scc
31/33
Strongly-ConnectedComponents
31
Graph G Graph G r
DF Spanning Forest of G r Strongly-connected components:
{G}, {H,I,J}, {B,A,C,F}, {D}, {E}
-
8/12/2019 Articulation Point, Scc
32/33
Strongly-ConnectedComponents: Analysis
CorrectnessIf v and w are in a strongly-connected componentThen there is a path from v to w and a path from
w to vTherefore, there will also be a path between v andw in G and G r
Running timeTwo executions of DFSO(|E|+|V|)
32
-
8/12/2019 Articulation Point, Scc
33/33
Summary
Graphs one of the most important datastructuresStudied for centuriesNumerous applicationsSome of the hardest problems to solveare graph problems
E.g., Hamiltonian (simple) cycle, Clique
33