Graph (III)
Trees, Articulation point, Bridge, SCC
GGuy19-3-2011
Review
Shortest pathDijkstraBellman FordFloyd Warshall
Minimum Spanning TreePrim’sKruskal’s
Tree
• The following four conditions are equivalent:– G is connected and acyclic– G is connected and |E| = |V| - 1 – G is acyclic and |E| = |V| - 1– Between any pair of vertices in G, there exists a
unique path• G is a tree if at least one of the above
conditions is satisfied
Tree
• |E| = |V| - 1• Between any pair of vertices, there is a unique path• Adding an edge between a pair of non-adjacent
vertices creates exactly one cycle• Removing an edge from the tree breaks the tree into
two smaller trees
Tree
root
siblings
descendants children
ancestors
parent
Tree Diameter
Find the farthest node from root, say it uFind the farthest node from u, say it v
(u, v) = Tree diameter
DFS TreeDFS (vertex u) {mark u as visited
time = time + 1birth[u] = time;for each vertex v directly reachable from u
if v is unvisitedparent[v] = uDFS (v)
time = time + 1death[u] = time;
}
A
F
B
C
D
E
GH
DFS forest (Demonstration)A B C D E F G H
birth
death
parent
unvisited
visited
visited (dead)
A
B
C
F
E
D
G
1 2 3 13 10 4 14
12 9 8 16 11 5 15
H
6
7
- A B - A C D C
Classification of edges
• Tree edge• Forward edge• Back edge• Cross edge
• Question: which type of edges is always absent in an undirected graph?
A
B
C
F
E
D
G
H
Determination of edge types
• How to determine the type of an arbitrary edge (u, v) after DFS?
• Tree edge– parent [v] = u
• Forward edge– not a tree edge; and– birth [v] > birth [u]; and– death [v] < death [u]
• How about back edge and cross edge?
Determination of edge types
Tree edge Forward Edge Back Edge Cross Edge
parent [v] = u
not a tree edgebirth[v] > birth[u]death[v] < death[u]
birth[v] < birth[u]death[v] > death[u]
birth[v] < birth[u]death[v] < death[u]
Articulation Point
For a undirected graph G,Node u is an Articulation Point if remove u from G will create more components.
Articulation Point
Bridge
For a undirected graph G,Edge (u, v) is an bridge if remove (u, v) from G will create more components.
Bridge
Finding AP and Bridge
DFS(vertex u)time = time + 1low[u] = vis[u] = timefor each vertex v directly reachable from u
if v is not visitedDFS(v)low[u] = min(low[u], low[v])
if v is visited and parent of u is not v
low[u] = min(low[u], vis[v])
Finding AP
Find the DFS tree of G and compute low[]
Vertex u is an AP if
1. u is the root and u has >1 children2. u is not the root and there exists children v where low[v] >= vis[u]
Finding Bridge
Find the DFS tree of G and compute low[]
Edge (u, v) is a Bridge if
1. v is u children and low[v] > vis[u]
Bi-connected component
A bi-connected component (or 2-connected component) is a maximal bi-connected subgraph
A bi-connected subgraph is a graph that has no articulation point
Bi-connected component
Each Bi-connected component isconnected by bridge
Each articulation point belongs to morethan one Bi-connected component
The Bi-connected components form a Tree
Bi-connected component
Strongly Connected Component
In a directed graph G, a Strongly Connected Component is a subgraph that there is a path from each vertex to every other vertex in the same SCC.
Strongly Connected Component
Finding SCC
• Compute the DFS forest of the graph G to get the death time of the vertices
• Reverse all edges in G to form G’• Compute a DFS forest of G’, but always choose
the vertex with the latest death time when choosing the root for a new tree
• The SCCs of G are the DFS trees in the DFS forest of G’
A
F
B
C
D
GH
SCC (Demonstration)
A
F
B
C
D
E
GH
A B C D E F G H
birth
death
parent
1 2 3 13 10 4 14
12 9 8 16 11 5 15
6
7
- A B - A C D C
D
G
A E B
F
C
H
SCC (Demonstration)
D
G
A E B
F
C
H
A
F
B
C
D
GH
E
Finding SCC
Assume (u, v) belongs to the same SCCWLOG, assume u is visited first. Since the exists a path from u to v, we havedeath[u] > death[v]
When we do DFS on G’, we will call DFS(u) first. Since there exists a path from v to u in G, then there exists path from u to v in G’, hence v and u will be in the same tree.
Iterative Depth Searching (IDS)
Bi – Directional Searching (BDS)