You are on page 1of 16

1

Connected Components
Section 3.2, Section 3.5
Connected Component of s
p Connected component containing s
n Set of all nodes which can be reached from s
(which have a path from s)
p BFS & DFS: graph traversal methods for
computing connected component of s
PDF created with pdfFactory trial version www.pdffactory.com
2
Connected Component of s
2
1
3
4 5
7
8
6
9
10
13
11
12
s
Connected Component of s
2
1
3
4 5
7
8
6
9
10
13
11
12
s
PDF created with pdfFactory trial version www.pdffactory.com
3
Connected Component of s
2
1
3
4 5
7
8
6
9
10
13
11
12
s
Connected Component of s
2
1
3
4 5
7
8
6
9
10
13
11
12
s
PDF created with pdfFactory trial version www.pdffactory.com
4
Connected Component of s
2
1
3
4 5
7
8
6
9
10
13
11
12
s
Connected Component of s
2
1
3
4 5
7
8
6
9
10
13
11
12
s
PDF created with pdfFactory trial version www.pdffactory.com
5
Connected Components
p Is there a connected component
associated with each node of the graph?
p What is the relationship between these
components?
Connected Components
p Is there a connected component
associated with each node of the graph?
p What is the relationship between these
components
[3.8] For any two nodes s and t in a graph, their connected
components are either identical or disjoint.
PDF created with pdfFactory trial version www.pdffactory.com
6
Connected Components
p [3.8] For any two nodes s and t in a
graph, their connected components are
either identical or disjoint.
Connected Components
p [3.8] For any two nodes s and t in a
graph, their connected components are
either identical or disjoint.
n Case 1: There is an s-t path. Then every node
u in the component of s is also in the
component of t and vice-versa: identical
PDF created with pdfFactory trial version www.pdffactory.com
7
Connected Components
p [3.8] For any two nodes s and t in a
graph, their connected components are
either identical or disjoint.
n Case 1: There is an s-t path. Then every node
u in the component of s is also in the
component of t and vice-versa: identical
p You can get from t s u: this gives a t-u path!
Connected Components
p [3.8] For any two nodes s and t in a
graph, their connected components are
either identical or disjoint.
n Case 1: There is an s-t path. Then every node
u in the component of s is also in the
component of t and vice-versa: identical
p You can get from t s u: this gives a t-u path!
n Case 2: There is no s-t path. No common node
u for components of s and t: disjoint
PDF created with pdfFactory trial version www.pdffactory.com
8
Connected Components
p [3.8] For any two nodes s and t in a
graph, their connected components are
either identical or disjoint.
n Case 1: There is an s-t path. Then every node
u in the component of s is also in the
component of t and vice-versa: identical
p You can get from t s u: this gives a t-u path!
n Case 2: There is no s-t path. No common node
u for components of s and t: disjoint
p Otherwise, there is a path s u t which is a
contradiction
Finding all connected components
PDF created with pdfFactory trial version www.pdffactory.com
9
Finding all connected components
p Start BFS from some node s. This gives
one component of the graph
Finding all connected components
p Start BFS from some node s. This gives
one component of the graph
p Pick any currently unexplored node u start
another BFS. This gives another
component.
PDF created with pdfFactory trial version www.pdffactory.com
10
Finding all connected components
p Start BFS from some node s. This gives
one component of the graph
p Pick any currently unexplored node u start
another BFS. This gives another
component.
p Continue in this manner until all nodes are
explored
Finding all connected components
p Start BFS from some node s. This gives
one component of the graph
p Pick any currently unexplored node u start
another BFS. This gives another
component
p Continue in this manner until all nodes are
explored
p Running time = O(m+n)
PDF created with pdfFactory trial version www.pdffactory.com
11
Connectivity in Directed Graphs
p Undirected graphs: s-t connectivity
p Directed graphs: s-t mutual connectivity
n Directed path from s to t
n Directed path from t to s
Mutual Connectivity
p [3.16] If u and v are mutually reachable,
and v and w are mutually reachable, then
u and w are mutually reachable.
PDF created with pdfFactory trial version www.pdffactory.com
12
Mutual Connectivity
p [3.16] If u and v are mutually reachable,
and v and w are mutually reachable, then
u and w are mutually reachable.
n To go from u to w, we can go via v
n To go from w to u, we can again to via v
Mutual Connectivity
p [3.16] If u and v are mutually reachable,
and v and w are mutually reachable, then
u and w are mutually reachable.
n To go from u to w, we can go via v
n To go from w to u, we can again to via v
Note: These paths need not be the same!
PDF created with pdfFactory trial version www.pdffactory.com
13
Strong Connectivity of Digraphs
p A Directed graph is strongly connected if
every two nodes u and v are mutually
reachable from each other
n Analogous to connectivity in undirected graph
Strong Components in Digraphs
p The strong component containing s is the
set of all nodes v such that s and v are
mutually reachable from each other.
n Analogous to connected component containing
s in undirected graphs.
PDF created with pdfFactory trial version www.pdffactory.com
14
Computing a strong component
p How to compute the strong component R
which contains s ?
Computing a strong component
p How to compute the strong component R
which contains s ?
n A = set of all nodes which have a path from s
n B = set of all nodes which have a path to s
n R = nodes in both A and B
PDF created with pdfFactory trial version www.pdffactory.com
15
Computing a strong component
p How to compute the strong component R
which contains s ?
n A = set of all nodes which have a path from s
n B = set of all nodes which have a path to s
n R = nodes in both A and B
How to compute A and B?
Set of all Strong Components
p For any node u in R, u and s are mutually
reachable
PDF created with pdfFactory trial version www.pdffactory.com
16
Set of all Strong Components
p For any node u in R, u and s are mutually
reachable
p Any two nodes u and v in R are mutually
reachable
n u and s are mutually reachable; s and v are
mutually reachable. Hence, u and v are
mutually reachable
Set of all Strong Components
p For any node u in R, u and s are mutually
reachable
p Any two nodes u and v in R are mutually
reachable
n u and s are mutually reachable; s and v are
mutually reachable. Hence, u and v are
mutually reachable
p For any two nodes u and v, the strong
components of u and v are either identical
or disjoint!
PDF created with pdfFactory trial version www.pdffactory.com

You might also like