Ch 8 - Graphs
Basic ideas introduced by Leonhard Euler (Swiss)
in 18th century
– He solved famous konigsberg bridge problem
Graphs actually can solve many types of problems:
– Whether a circuit can be used on a planar
circuit board
– Whether 2 computers are connected by a
communications link (any networks)
– Finding shortest path between 2 cities in a
transportation network
– … Scheduling (precedence graphs),
relationships, chemical structures,…
1
Copyright M.R.K. Krishna Rao 2003
Introduction to Graphs
Graphs are discrete structures consisting of
vertices and edges that connect these vertices.
– undirected edge: an edge associated to a set
{u,v} where u and v are vertices.
– directed edge: an edge associated to an
ordered pair (u,v) where u and v are vertices.
– multiple edges: distinct edges connecting the
same vertices.
– loop: an edge connecting a vertex with itself.
There are several different types of graphs that
differ with respect to the kind and number of
edges that connect a pair of vertices.
2
Copyright M.R.K. Krishna Rao 2003
Simple Graph
Definition: A simple graph G = (V, E) consists of
V, a nonempty set of vertices, and E, a set
of unordered pairs of distinct elements of V
called edges.
Detroit
New York
San Francisco
Chicago
Denver
Los Angeles
Washington
A computer Network
3
Copyright
M.R.K.
Krishna Rao
2003 are they?
How many vertices? How
many
edges?
What
Simple Graph - example
SET OF VERTICES
V = { Chicago, Denver, Detroit, Los Angeles,
New York, San Francisco, Washington }
SET OF EDGES
E = { {San Francisco, Los Angeles},
{San Francisco, Denver},
{Los Angeles, Denver},
{Denver, Chicago},
{Chicago, Detroit},
{Detroit, New York},
{New York, Washington},
{Chicago, Washington},
{Chicago, New York} }
Copyright M.R.K. Krishna Rao 2003
4
A Non-Simple Graph
Definition: In a multigraph G = (V, E) two or
more edges may connect the same pair of
vertices.
Detroit
New York
San Francisco
Chicago
Denver
Los Angeles
Washington
THERE CAN BE MULTIPLE TELEPHONE LINES
BETWEEN TWO COMPUTERS IN THE NETWORK.
Two edges are called multiple or parallel edges
if they connect the same two distinct vertices.
Copyright M.R.K. Krishna Rao 2003
5
Another Non-Simple Graph
Definition: In a pseudograph G = (V, E) two or
more edges may connect the same pair of
vertices, and in addition, an edge may connect
a vertex to itself.
Detroit
New York
San Francisco
Chicago
Denver
Los Angeles
Washington
THERE CAN BE TELEPHONE LINES IN THE NETWORK
FROM A COMPUTER TO ITSELF (for diagnostic use).
An edge is called a loop if it connects a vertex to itself.
6
Copyright M.R.K. Krishna Rao 2003
Undirected Graphs
pseudographs
multigraphs
simple graphs
7
Copyright M.R.K. Krishna Rao 2003
Directed Graphs
Definition: In a directed graph G = (V, E) the
edges are ordered pairs of (not necessarily
distinct) vertices.
Detroit
New York
Chicago
San Francisco
Denver
Washington
Los Angeles
SOME TELEPHONE LINES IN THE NETWORK
MAY OPERATE IN ONLY ONE DIRECTION .
Those that operate in two directions are represented by
pairs of edges in opposite directions.
8
Copyright M.R.K. Krishna Rao 2003
Types of Graphs and Their
Properties
TYPE
EDGES
Simple
MULTIPLE LOOPS
EDGES OK? OK?
Undirected No
No
Multigraph
Undirected Yes
No
Pseudograph Undirected Yes
Yes
Directed
graph
Directed
multigraph
Directed
No
Yes
Directed
Yes
Yes
9
Copyright M.R.K. Krishna Rao 2003
Graph Models
Example: How can we represent a network of (bidirectional) railways connecting a set of cities?
We should use a simple graph with an edge {a, b}
indicating a direct train connection between cities a
and b.
Toronto
Boston
Lübeck
New York
Hamburg
Washington
10
Copyright M.R.K. Krishna Rao 2003
Graph Models
Example: In a round-robin tournament, each team
plays against each other team exactly once. How
can we represent the results of the tournament
(which team beats which other team)?
We should use a directed graph with an edge (a, b)
indicating that team a beats team b.
Bruins
Maple Leafs
Penguins
Lübeck Giants
11
Copyright M.R.K. Krishna Rao 2003
Graph Models
Niche Overlap Graph in ecology: model interaction of
different species of animals; each species is
represented by a vertex; an undirected edge
connects 2 vertices if the 2 species compete (for
the same food resources, etc.)
Raccoon
Hawk
Owl
Crow
Opossum
Squirrel
Woodpecker
12
Copyright M.R.K. Krishna Rao 2003
Graph Models
Precedence Graph and Concurrent
Processing : model of dependence of
certain statements in a program on
other statements in it. Dependence
can be shown by a directed graph.
Each statement is depicted by a
vertex, and there’s an edge from one
vertex to a second vertex if the
statement represented by the second
vertex can’t be executed before the
previous one has been executed.
13
Copyright M.R.K. Krishna Rao 2003
Precedence Graph and Concurrent
Processing
S1
S2
S3
S4
S5
S6
S6
a := 0
b := 1
c := a + 1
d := b + a
e := d + 1
e := c + d
S5
S3
S4
Note: statement S5 can’t be
executed before statements
S1, S2, and S4 are executed.
S1
S2
14
Copyright M.R.K. Krishna Rao 2003
5.2 Graph Terminology
Definition: Two vertices u and v in an undirected
graph G are called adjacent (or neighbors) in G
if there is an edge e = {u, v} in G.
The edge e connects u and v and is incident with
u and v. The vertices u and v are called endpoints
of the edge {u, v}.
Definition: The degree of a vertex in an
undirected graph is the number of edges
incident with it, except that a loop at a vertex
contributes twice to the degree of that vertex.
The degree of the vertex v is denoted by deg(v).
A vertex of degree 0 is called isolated. A vertex
of degree 1 is called pendant.
15
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Example: Which vertices in the following graph are
isolated, which are pendant, and what is the
maximum degree? What type of graph is it?
d
a
b
f
c
e
f
g
h
j
Solution: Vertex f is isolated, and vertices a, d and
j are pendant. The maximum degree is deg(g) = 5.
This graph is a pseudograph (undirected, loops).
16
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Let us look at the same graph again and determine
the number of its edges and the sum of the
degrees of all its vertices:
d
a
b
f
c
e
f
g
h
j
Result: There are 9 edges, and the sum of all
degrees is 18. This is easy to explain: Each new
edge increases the sum of degrees by exactly two.
17
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
The Handshaking Theorem: Let G = (V, E) be an
undirected graph with e edges. Then
2e = vV deg(v)
Note: This theorem holds even if multiple edges
and/or loops are present.
Example: How many edges are there in a graph
with 10 vertices, each of degree 6?
Solution: The sum of the degrees of the vertices is
610 = 60. According to the Handshaking Theorem,
it follows that 2e = 60, so there are 30 edges.
18
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Theorem: An undirected graph has an even
number of vertices of odd degree.
Proof: Let V1 and V2 be the set of vertices
of even and odd degree respectively, in an
undirected graph G(V,E). By Handshake
Theorem,
2e = vV deg(v) = vV1 deg(v) + vV2 deg(v).
Since vertices in V1 are of even degree, the
first sum is even. Hence the second sum
should be even too.
QED.
19
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Theorem: An undirected graph has an even number
of vertices of odd degree.
Grandma’s proof: There are three possibilities for
adding an edge to connect two vertices in the graph:
Before:
After:
Both vertices have
even degree
Both vertices have
odd degree
Both vertices have
odd degree
Both vertices have
even degree
One vertex has odd
degree, the other even
One vertex has even
degree, the other odd
20
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
There are two possibilities for adding a loop
to a vertex in the graph:
Before:
After:
The vertex has
even degree
The vertex has
even degree
The vertex has
odd degree
The vertex has
odd degree
21
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
So if there is an even number of vertices of odd
degree in the graph, it will still be even after
adding an edge.
Therefore, since an undirected graph with no
edges has an even number of vertices with odd
degree (zero), the same must be true for any
undirected graph.
Thank you, grandma !
22
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Definition: When (u, v) is an edge of the graph
G with directed edges, u is said to be adjacent
to v, and v is said to be adjacent from u.
The vertex u is called the initial vertex of (u,
v), and v is called the terminal vertex of (u, v).
Note: The initial vertex and terminal vertex of
a loop are the same.
Definition: In a graph with directed edges, the
in-degree of a vertex v, denoted by deg-(v), is
the number of edges with v as their terminal
vertex.
The out-degree of v, denoted by deg+(v), is the
number of edges with v as their initial vertex.
23
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Example: What are the in-degrees and outdegrees of the vertices a, b, c, d in this graph:
deg-(a) = 1
deg+(a) = 2
deg-(d) = 2
deg+(d) = 1
a
d
b
c
deg-(b) = 4
deg+(b) = 2
deg-(c) = 0
deg+(c) = 2
24
Copyright M.R.K. Krishna Rao 2003
Graph Terminology
Theorem: Let G = (V, E) be a graph with directed
edges. Then:
vV deg-(v) = vV deg+(v) = |E|
This is easy to see, because every new edge
increases both the sum of in-degrees and the sum
of out-degrees by one.
25
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Definition: The complete graph on n vertices,
denoted by Kn, is the simple graph that contains
exactly one edge between each pair of distinct
vertices.
K1
K2
K3
K4
K5
26
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Definition: The cycle Cn, n 3, consists of n
vertices v1, v2, …, vn and edges {v1, v2}, {v2, v3}, …,
{vn-1, vn}, {vn, v1}.
C3
C4
C5
C6
27
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Definition: We obtain the wheel Wn when we add
an additional vertex to the cycle Cn, for n 3, and
connect this new vertex to each of the n vertices
in Cn by adding new edges.
W3
W4
W5
W6
28
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Definition: The n-cube, denoted by Qn, is the
graph that has vertices representing the 2n bit
strings of length n. Two vertices are adjacent if
and only if the bit strings that they represent
differ in exactly one bit position.
110
10
0
1
Q1
11
111
100
101
010
00
01
011
000
Q2
001
Q3
29
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Definition: A simple graph is called bipartite if its
vertex set V can be partitioned into two disjoint
nonempty sets V1 and V2 such that every edge in
the graph connects a vertex in V1 with a vertex in
V2 (so that no edge in G connects either two
vertices in V1 or two vertices in V2).
For example, consider a graph that represents
each person in a village by a vertex and each
marriage by an edge.
This graph is bipartite, because each edge
connects a vertex in the subset of males with a
vertex in the subset of females (if we think of
traditional marriages).
30
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Example: Is C3 bipartite?
v1
v2
v3
No, because there is no way to
partition the vertices into two sets
so that there are no edges with
both endpoints in the same set.
Example: Is C6 bipartite?
v1
v6
Yes, because
v2
v5 we can display
C6 like this:
v3
v4
v1
v5
v3
v6
v2
v4
31
Copyright M.R.K. Krishna Rao 2003
Special Graphs
Definition: The complete bipartite graph Km,n is
the graph that has its vertex set partitioned into
two subsets of m and n vertices, respectively. Two
vertices are connected if and only if they are in
different subsets.
K3,2
K3,4
32
Copyright M.R.K. Krishna Rao 2003
Applications of special graphs
Local Area Networks
Star
Ring
Star + Ring
hybrid
33
Copyright M.R.K. Krishna Rao 2003
Applications of special graphs
Interconnection Networks for Parallel
Computation:
Linear array:
Mesh network:
Hypercube: n-cube
Linear array of 6 processors
Mesh of 16 processors
Hypercube of 8 processors
Copyright M.R.K. Krishna Rao 2003
34
Operations on Graphs
Definition: A subgraph of a graph G = (V, E) is a
graph H = (W, F) where WV and FE.
Note: Of course, H is a valid graph, so we cannot
remove any endpoints of remaining edges when
creating H.
Example:
K5
subgraph of K5
35
Copyright M.R.K. Krishna Rao 2003
Operations on Graphs
Definition: The union of two simple graphs G1 =
(V1, E1) and G2 = (V2, E2) is the simple graph with
vertex set V1 V2 and edge set E1 E2.
The union of G1 and G2 is denoted by G1 G2.
G1
G2
G1 G2 = K5
36
Copyright M.R.K. Krishna Rao 2003
5.3 Representing Graphs
a
d
b
d
c
Vertex
a
b
c
d
Adjacent
Vertices
b, c, d
a, d
a, d
a, b, c
a
b
c
Initial
Vertex
a
b
c
d
Terminal
Vertices
c
a
a, b, c
37
Copyright M.R.K. Krishna Rao 2003
Representing Graphs
Definition: Let G = (V, E) be a simple graph with
|V| = n. Suppose that the vertices of G are
listed in arbitrary order as v1, v2, …, vn.
The adjacency matrix A (or AG) of G, with
respect to this listing of the vertices, is the nn
zero-one matrix with 1 as its (i, j)th entry when
vi and vj are adjacent, and 0 otherwise.
In other words, for an adjacency matrix A = [aij],
aij = 1
if {vi, vj} is an edge of G,
aij = 0
otherwise.
38
Copyright M.R.K. Krishna Rao 2003
Representing Graphs
Example: What is the adjacency
matrix AG for the following
graph G based on the order of
vertices a, b, c, d ?
Solution:
0
1
AG
1
1
a
d
b
c
1 1 1
0 0 1
0 0 1
1 1 0
Note: Adjacency matrices of undirected graphs
are always symmetric.
39
Copyright M.R.K. Krishna Rao 2003
Representing Graphs
For the representation of graphs with multiple edges,
we can no longer use zero-one matrices.
Instead, we use matrices of natural numbers.
The (i, j)th entry of such a matrix equals the number
of edges that are associated to {vi, vj}.
Example: What is the adjacency matrix AG for the
following graph G based on the order of vertices a, b,
c, d ?
a
0 1 1 2
1 1 0 1
Solution: AG
b
d
1 0 0 3
c
2 1 3 0
40
Copyright M.R.K. Krishna Rao 2003
Representing Directed Graphs
Definition: Let G = (V, E) be a directed graph with
|V| = n. Suppose that the vertices of G are listed in
arbitrary order as v1, v2, …, vn. The adjacency
matrix A (or AG) of G, with respect to this listing
of the vertices, is the nn zero-one matrix with 1
as its (i, j)th entry when there is an edge from vi to
vj, and 0 otherwise.
In other words, for an adjacency matrix A = [aij],
aij = 1
if (vi, vj) is an edge of G,
aij = 0
otherwise.
41
Copyright M.R.K. Krishna Rao 2003
Representing Directed Graphs
Example: What is the adjacency
matrix AG for the following
graph G based on the order of
vertices a, b, c, d ?
Solution:
0
1
AG
0
1
a
d
b
c
0 1 0
0 0 0
0 0 0
1 1 0
42
Copyright M.R.K. Krishna Rao 2003
Representing Graphs
Definition: Let G = (V, E) be an undirected graph
with |V| = n. Suppose that the vertices and edges
of G are listed in arbitrary order as v1, v2, …, vn and
e1, e2, …, em, respectively.
The incidence matrix of G with respect to this
listing of the vertices and edges is the nm zeroone matrix with 1 as its (i, j)th entry when edge ej
is incident with vi, and 0 otherwise.
In other words, for an incidence matrix M = [mij],
mij = 1
if edge ej is incident with vi
mij = 0
otherwise.
43
Copyright M.R.K. Krishna Rao 2003
Representing Graphs
Example: What is the incidence
matrix M for the following
graph G based on the order of
vertices a, b, c, d and edges 1, 2,
3, 4, 5, 6?
Solution:
1
1
M
0
0
1 0 0 1 0
0 1 0 0 0
0 0 1 1 1
1 1 1 0 0
a
2
d
1
3
b
5
4
c
6
44
Copyright M.R.K. Krishna Rao 2003
Isomorphism of Graphs
Definition: The simple graphs G1 = (V1, E1) and G2 =
(V2, E2) are isomorphic if there is a bijection (an
one-to-one and onto function) f from V1 to V2 with
the property that a and b are adjacent in G1 if and
only if f(a) and f(b) are adjacent in G2, for all a and
b in V1.
Such a function f is called an isomorphism.
In other words, G1 and G2 are isomorphic if their
vertices can be ordered in such a way that the
adjacency matrices MG1 and MG2 are identical.
45
Copyright M.R.K. Krishna Rao 2003
Isomorphism of Graphs
From a visual standpoint, G1 and G2 are isomorphic
if they can be arranged in such a way that their
displays are identical (of course without changing
adjacency).
Unfortunately, for two simple graphs, each with n
vertices, there are n! possible isomorphisms that
we have to check in order to show that these
graphs are isomorphic.
However, showing that two graphs are not
isomorphic can be easy.
46
Copyright M.R.K. Krishna Rao 2003
Isomorphism of Graphs
For this purpose we can check invariants, that is,
properties that two isomorphic simple graphs must
both have.
For example, they must have
– the same number of vertices,
– the same number of edges, and
– the same degrees of vertices.
– the same types of subgraphs
– the same with any other basic property
Note that two graphs that differ in any of these
invariants are not isomorphic, but two graphs that
match in all of them are not necessarily isomorphic.
47
Copyright M.R.K. Krishna Rao 2003
Isomorphism of Graphs
Example I: Are the following two graphs isomorphic?
a
a
b
c
e
d
c
b
e
d
Solution: Yes, they are isomorphic, because they
can be arranged to look identical. You can see this
if in the right graph you move vertex b to the left
of the edge {a, c}. Then the isomorphism f from
the left to the right graph is: f(a) = e, f(b) = a,
f(c) = b, f(d) = c, f(e) = d.
48
Copyright M.R.K. Krishna Rao 2003
Isomorphism of Graphs
Example II: How about these two graphs?
b
c
a
a
e
b
d
c
e
d
Solution: No, they are not isomorphic, because
they differ in the degrees of their vertices.
Vertex d in right graph is of degree one, but there
is no such vertex in the left graph.
49
Copyright M.R.K. Krishna Rao 2003
Graph Isomorphism -ve Examples
To show that two graphs are non-isomorphic, we
need to show that no function can exist that
satisfies defining properties of isomorphism.
In practice, we try to find some intrinsic
property that differs between the 2 graphs.
Q: Why are the following non-isomorphic?
u2
u1
u5
u3
v2
v1
u4
v3
v4
50
Copyright M.R.K. Krishna Rao 2003
Graph Isomorphism
-Negative Examples
A: 1st graph has more vertices than 2nd.
Q: Why are the following non-isomorphic?
u2
u1
u5
u3
u4
v2
v1
v5
v3
v4
51
Copyright M.R.K. Krishna Rao 2003
Graph Isomorphism
-Negative Examples
A: 1st graph has more edges than 2nd.
Q: Why are the following non-isomorphic?
u2
u1
u5
u3
u4
v2
v1
v5
v3
v4
52
Copyright M.R.K. Krishna Rao 2003
Graph Isomorphism
-Negative Examples
A: 2nd graph has vertex of degree 1, 1st graph
doesn't.
Q: Why are the following non-isomorphic?
u1
u2
u3
u7
u8
u4
u5
u9
u6
v1
v2
v7
v3
v4
v5
v8
v9
53
Copyright M.R.K. Krishna Rao 2003
v6
Graph Isomorphism
-Negative Examples
A: 1st graph has 2 degree 1 vertices, 4 degree
2 vertex and 2 degree 3 vertices. 2nd graph
has 3 degree 1 vertices, 3 degree 2 vertex
and 3 degree 3 vertices.
Q: Why are the following non-isomorphic?
u1
u2
u7
u3
u4
u5
u8
u6
v1
v2
v7
v3
v4
v5
v8
54
Copyright M.R.K. Krishna Rao 2003
v6
Graph Isomorphism
-Negative Examples
u1
A: None of the previous approaches work as
there are the same no. of vertices, edges, and
same no. of vertices per degree.
u2
u3
u4
u5 u6
v1 v 2
v3
v4
v5
u7
u8
v7
v8
LEMMA: If G and H are isomorphic, then any
subgraph of G will be isomorphic to some
subgraph of H.
Q: Find a subgraph of 2nd graph which isn’t a
subgraph of 1st graph.
Copyright M.R.K. Krishna Rao 2003
55
v6
Graph Isomorphism
-Negative Examples
u1
A: This subgraph is not a subgraph of the left
graph.
u2
u3
u4
u5
u6
v1
v2
v3
v4
v5
u7
u8
v7
v8
Why not? Deg. 3 vertices must map to deg. 3
vertices. Since subgraph and left graph are
symmetric, can assume v2 maps to u2. Adjacent
deg. 1 vertices to v2 must map to degree 1
vertices, forcing the deg. 2 adjacent vertex v3 to
map to u3. This forces the other vertex adjacent
to v3, namely v4 to map to u4. But then a deg. 3
vertex has mapped to a deg. 2 vertex • 56
Copyright M.R.K. Krishna Rao 2003
v6
5.4 Graphs and Connectivity
Some problems can be modeled using paths
Example: determining whether messages can
be sent between 2 computers using
intermediate links can be done using graphs
Planning routes for package delivery, garbage
pickup, diagnostics in computer networks,
etc. can be solved using models that utilize
paths in graphs
57
Copyright M.R.K. Krishna Rao 2003
Connectivity
Definition: A path of length n from u to v, where n is a
positive integer, in an undirected graph is a sequence
of edges e1, e2, …, en of the graph such that
e1 = {x0, x1}, e2 = {x1, x2}, …, en = {xn-1, xn},
where x0 = u and xn = v. The path is said to pass
through or traverse x1, x2, …, xn-1.
When the graph is simple, we denote this path by its
vertex sequence x0, x1, …, xn, since it uniquely
determines the path.
The path is a circuit if it begins and ends at the same
vertex, that is, if u = v.
A path or circuit is simple if it does not contain the
same edge more than once.
58
Copyright M.R.K. Krishna Rao 2003
Connectivity
Definition: A path of length n from u to v, where n
is a positive integer, in a directed multigraph is a
sequence of edges e1, e2, …, en of the graph such
that e1 = (x0, x1), e2 = (x1, x2), …, en = (xn-1, xn),
where x0 = u and xn = v.
When there are no multiple edges in the path, we
denote this path by its vertex sequence x0, x1, …,
xn, since it uniquely determines the path.
The path is a circuit if it begins and ends at the
same vertex, that is, if u = v.
A path or circuit is called simple if it does not
contain the same edge more than once.
59
Copyright M.R.K. Krishna Rao 2003
Connectivity
Definition: An undirected graph is called connected
if there is a path between every pair of distinct
vertices in the graph.
For example, any two computers in a network can
communicate if and only if the graph of this
network is connected.
Note: A graph consisting of only one vertex is
always connected, because it does not contain any
pair of distinct vertices.
60
Copyright M.R.K. Krishna Rao 2003
Connectivity
Example: Are the following graphs connected?
a
b
c
b
c
b
a
e
d
Yes.
No.
b
e
d
Yes.
d
c
a
e
c
a
d
f
e
No.
61
Copyright M.R.K. Krishna Rao 2003
Connectivity
Theorem: There is a simple path between every pair of
distinct vertices of a connected undirected graph.
Proof: We claim that the shortest path between
distinct vertices x0 and xn, represented as a sequence
of vertices x0, x1, … , xn, is simple.
To see this, suppose it is not simple. Then xi = xj for
some i and j with 0 = i < j.
This means that there is a path from x0 to xn of
shorter length with vertex sequence x0, x1, … , xi-1, xj,
… , xn obtained by deleting the edges corresponding to
the vertex sequence xi, … , xj-1. This is a contradiction.
62
Copyright M.R.K. Krishna Rao 2003
Connectivity
Definition: A graph that is not connected is the
union of two or more connected subgraphs, each
pair of which has no vertex in common. These
disjoint connected subgraphs are called the
connected components of the graph.
Definition: A directed graph is strongly
connected if there is a path from a to b and from
b to a whenever a and b are vertices in the graph.
Definition: A directed graph is weakly connected
if there is a path between any two vertices in the
underlying undirected graph.
63
Copyright M.R.K. Krishna Rao 2003
Connectivity
Example: What are the connected components in
the following graph?
d
a
b
i
c
e
f
g
h
j
Solution: The connected components are the
graphs with vertices {a, b, c, d}, {e}, {f}, {g, h, i, j}.
64
Copyright M.R.K. Krishna Rao 2003
Connectivity
Example: Are the following directed graphs
strongly or weakly connected?
a
b
d
a
d
c
b
c
Weakly connected, because,
for example, there is no path
from b to d.
Strongly connected, because
there are paths between all
possible pairs of vertices.
65
Copyright M.R.K. Krishna Rao 2003
Cut Vertex or Cut Edge
A vertex v is called a cut vertex (or articulation
point) If its removal will produce a subgraph
with more connected components than in the
original graph.
An edge e is called a cut edge (or bridge) if its
removal will produce a subgraph with more
connected components than in the original graph.
a
d
b
c
c is a cut vertex
(d,c) is a cut edge
66
Copyright M.R.K. Krishna Rao 2003
Connectivity
Idea: The number and size of connected
components and circuits are further invariants with
respect to isomorphism of simple graphs.
Example: Are these two graphs isomorphic?
Solution: No, because the right graph contains
circuits of length 3, while the left graph does not.
Try Example 10 on page 461.
Copyright M.R.K. Krishna Rao 2003
67
Number of Paths of Length r
between Vertices
Theorem: Let G be a graph with adjacency matrix A
with respect to the ordering
v1 , v 2 , . . . , vn
. The number of different paths of length r from
vi to vj , where r is a positive integer, equals the
entry in row i and column j of Ar.
NOTE: This applies with directed or undirected
edges, with multiple edges and loops allowed.
Try Example 8 on Page 472/473!
68
Copyright M.R.K. Krishna Rao 2003
Euler Path
(the Konigsberg Bridge problem)
c
a
b
c
d
a
d
b
Is there a simple circuit in the given multigraph
that contains every edge?
An Euler circuit in a graph G is a simple circuit
containing every edge of G.
An Euler path in a graph G is a simple path
69
containing everyCopyright
edge
of
G.
M.R.K. Krishna Rao 2003
Euler and Hamilton Paths
-Motivation
An pictorial way to motivate the
graph theoretic concepts of
Eulerian and Hamiltonian paths and
circuits is to use two puzzles:
– The pencil drawing problem
– The taxicab problem
70
Copyright M.R.K. Krishna Rao 2003
Pencil Drawing Problem
-Euler Paths
Which of the following pictures can be drawn
on paper without ever lifting the pencil and
without retracing over any segment?
71
Copyright M.R.K. Krishna Rao 2003
Pencil Drawing Problem
-Euler Paths
Graph Theoretically: Which of the following
graphs has an Euler path?
72
Copyright M.R.K. Krishna Rao 2003
Pencil Drawing Problem
-Euler Paths
Answer: the left but not the right.
1
2
3
start
4
finish
6
5
73
Copyright M.R.K. Krishna Rao 2003
Taxicab Problem
-Hamilton Paths
Can a taxicab driver milk his hapless
customer by visiting every intersection
exactly once, when driving from point A to
point B ?
A
Copyright M.R.K. Krishna Rao 2003
B
74
Taxicab Problem
-Hamilton Paths
Graph Theoretically: Is there a Hamilton
path from A to B in the following graph?
(NO in this case)
A
Copyright M.R.K. Krishna Rao 2003
B
75
Euler Circuits and Paths
Necessary and Suficient Conditions for
Euler Circuits and Paths
Theorem 1: A connected multigraph has a
Euler circuit if and only if each of its
vertices has even degree.
Theorem 2: A connected multigraph has a
Euler path but not a Euler circuit if and only
if it has exactly two vertices of odd degree.
76
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
Constructive proof (algorithm)
1) Find a simple cycle in connected graph.
2) Delete all the edges from the cycle and
find Euler cycles in each resulting
component
3) Amalgamate Euler cycles together using
the simple cycle obtaining wanted Euler
cycle.
Let’s see how the amalgamation process works:
77
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
Find a cycle starting from some vertex.
Then delete all its edges.
78
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
Now try again (say from middle vertex).
79
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
Amalgamate these cycles together from a point
of intersection, and delete from graph:
80
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
9
1
2
3
8
10
7
11
6
4
5
Find another cycle from middle vertex:
81
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
9
1
2
3
8
10
7
11
6
4
5
Amalgamate it to Euler cycle of deleted
graph, and delete it. Need to insert cycle
between former edges 10 & 11:
82
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
9
10
1
2
3
8
14
11
15
4
13
12
5
7
6
Use same naïve approach looking for cycle in
remaining component:
83
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
9
10
1
2
3
8
14
11
15
4
13
12
5
7
6
Amalgamate the triangle cycle between
edges formerly labeled 9 & 10:
84
Copyright M.R.K. Krishna Rao 2003
Finding Euler Circuits
We found the Euler circuit!
9
10
11
12
1
2
3
13
8
17
14
18
4
16
15
5
7
6
85
Copyright M.R.K. Krishna Rao 2003
Euler Circuits and Paths
Try these – which of the undirected graphs
below have an Euler circuit? Of those that
do not, which have an Euler path?
86
Copyright M.R.K. Krishna Rao 2003
Euler Circuits and Paths
Try these – which of the undirected graphs below
have an Euler circuit? Of those that do not, which
have an Euler path?
Euler circuit no path/circuit euler path
a,e,c,d,e,b,a
a,c,d,e,b,d,a,b
87
Copyright M.R.K. Krishna Rao 2003
Euler Paths?
Yes
Yes
Copyright M.R.K. Krishna Rao 2003
No
Hamilton Path
A Hamilton path in a graph G is a
simple path containing every
vertex of G exactly once.
a,b,c,d
Copyright M.R.K. Krishna Rao 2003
Hamilton Circuit
A Hamilton circuit in a graph G is a
simple circuit containing every vertex
of G exactly once.
a,b,c,d,e,a
Copyright M.R.K. Krishna Rao 2003
Hamilton Circuits and Paths
Try these – Hamilton Paths and Circuits: which of
the graphs below have a hamilton circuit, or if not,
a hamilton path?
91
Copyright M.R.K. Krishna Rao 2003
Hamilton Circuits and Paths
Try these – Hamilton Paths and Circuits: which of
the graphs below have a hamilton circuit, or if not,
a hamilton path?
Neither
Path
Path
92
Copyright M.R.K. Krishna Rao 2003
Hamilton Circuits and Paths
Note: there are NO known simple necessary and
sufficient criteria for the existence of
Hamilton circuits. However, we know:
Theorem: If G is a connected simple graph with n
vertices where n >= 3, then G has a Hamilton
circuit if the degree of each vertex is at least
n/2.
Theorem: Kn has a Hamilton circuit if n >= 3.
Fact: A graph with a vertex of degree 1 cannot
have a Hamilton circuit.
Fact: A graph with 3 vertices of degree 1 cannot
have a Hamilton path.
93
Copyright M.R.K. Krishna Rao 2003
7.7 - Planar Graphs
Planar graphs are graphs that can be drawn in
the plane without edges having to cross.
Understanding planar graph is important:
Any graph representation of maps/
topographical information is planar.
– graph algorithms often specialized to
planar graphs (e.g. traveling salesperson)
Circuits usually represented by planar graphs
94
Copyright M.R.K. Krishna Rao 2003
Planar Graphs
Just because a graph is drawn with edges
crossing doesn’t mean its not planar.
Q: Why can’t we conclude that the following is
non-planar?
95
Copyright M.R.K. Krishna Rao 2003
Planar Graphs
A: Because it is isomorphic to a graph which is
planar:
96
Copyright M.R.K. Krishna Rao 2003
Proving Planarity
To prove that a graph is planar amounts to
redrawing the edges in a way that no edges will
cross. We may need to move vertices around
and the edges may have to be drawn in a very
indirect fashion.
Example. show that the 3-cube is planar:
97
Copyright M.R.K. Krishna Rao 2003
(Dis)Proving Planarity - 4-Cube
Seemingly not planar, but how would one
prove this!
98
Copyright M.R.K. Krishna Rao 2003
Disproving Planarity - K3,3
Example: show that K3,3 is is not planar.
Proof: Suppose K3,3 is planar. Then v1, v2, v4, and v5
form a ‘square’.
Assume that v3 is inside this square. Then connecting
v3 to v4 and v5, the plane is divided into three regions.
Clearly, since v6 is incident with v1, v2, and v3, it cannot
be in any of the three regions without causing edge
crossing. This is a contradiction.
A similar argument can be used when v3 is outside.
99
Copyright M.R.K. Krishna Rao 2003
Disproving Planarity
The idea is to try to find some invariant
quantities possessed by graphs which are
constrained to certain values, for planar
graphs. Then to show that a graph is nonplanar, compute the quantities and show that
they do not satisfy the constraints on planar
graphs.
100
Copyright M.R.K. Krishna Rao 2003
Regions
The first invariant of a planar graph will be the
number of regions that the graph defines in
the plane. A region is a part of the plane
completely disconnected off from other parts
of the plane by the edges of the graph.
Example: the car graph has 4 regions:
4
3
1
2
Copyright M.R.K. Krishna Rao 2003
101
Regions
Q: How many regions does the 3-cube
have?
102
Copyright M.R.K. Krishna Rao 2003
Regions
Theorem: The number of regions defined by a
connected planar graph is invariant of how it is
drawn in the plane and satisfies the formula
involving edges and vertices:
r = |E | - |V | + 2
Example: Verify formula for car and 3-cube:
4=6-4+2
3
3
1
6=12-8+2
2
Copyright M.R.K. Krishna Rao 2003
4
1
5103
2
Euler Characteristic
The formula is proved by showing that the
quantity (chi) c = r - |E | + |V | must equal 2
for planar graphs. c is called the Euler
characteristic. The idea is that any
connected planar graph can be built up from
a vertex through a sequence of vertex and
edge additions. For example, build 3-cube as
follows:
104
Copyright M.R.K. Krishna Rao 2003
Euler Characteristic
105
Copyright M.R.K. Krishna Rao 2003
Euler Characteristic
Thus to prove that c is always 2 for
planar graphs, one calculate c for
the trivial vertex graph:
c = 1-0+1 = 2
and then checks that each possible
move does not change c .
106
Copyright M.R.K. Krishna Rao 2003
Euler Characteristic
Check that moves don’t change c :
(1) Adding a degree 1 vertex:
r is unchanged. |E | increases by 1.
|V | increases by 1. c += (0-1+1)
2) Adding an edge between preexisting vertices:
EG:
EG:
r increases by 1. |E | increases by 1.
|V | unchanged. c += (1-1+0)
107
Copyright M.R.K. Krishna Rao 2003
Euler Theorem – math proof
Theorem: Let G be a connected planar simple
graph with e edges and v vertices. Let r be
the number of regions in a planar
representation of G. Then r = e – v + 2.
Proof: The proof is by mathematical
induction.
Consider a sequence of subgraphs G1, G2, … Ge
= G of G, where G1 is an edge of G, and Gn+1
is obtained from Gn by adding to Gn an
edge {a,b} of G that is not in Gn; we
assume that vertex a orb is already in Gn.
For the base case G1, we have r = e – v + 2,
since r = 1, e = 1, and v = 2.
108
Copyright M.R.K. Krishna Rao 2003
Euler Theorem – math proof…
Induction Step: Suppose r = e – v + 2 is true for Gn.
Then we have two cases when adding an edge
{a,b} to Gn to obtain Gn+1 :
(1) a is in Gn but b is not; (2) both a and b are in Gn.
In case (1), we still have r = e – v + 2 since r is not
changed, and e and v are both increased by one.
In case (2), we also have r = e – v + 2 since r and e
are both increased by one, and v is not changed.
EG:
EG:
109
Copyright M.R.K. Krishna Rao 2003
Face-Edge Handshaking
For all graphs handshaking theorem relates
degrees of vertices to number of edges.
For planar graphs, can relate regions to
edges in similar fashion:
Example: There are two ways to count the
number of edges in 3-cube:
Count directly: 12
Count no. of edges around all
regions; and then divide by 2:
(4+4+4+4+4+4)/2 = 12 (2 triangles per edge)
Face-Edge Handshaking
DEF: The degree of a region F is the
number of edges at its boundary, and is
denoted by deg(F ).
Theorem: Let G be a planar graph with region
set R. Then:
1
| E | deg( F )
2 FR
111
Copyright M.R.K. Krishna Rao 2003
Euler Theorem – Corollary 1
Corollary 1: If G is a connected planar simple graph
with e edges and v 3 vertices, then e 3v – 6.
Proof: Let r be the number regions (faces) in the
graph. Every face has at least 3 edges on its
boundary. By face-edge handshaking theorem, 2e
= fR deg(f) 3r. Hence 2e/3 r.
Using Euler’s formula (r = e – v + 2), we get
e – v + 2 e/3 and hence e/3 v – 2.
Therefore, e 3v – 6.
QED.
Example: Prove that K5 is not planar.
Proof: Suppose K5 is planar. Then by the
Above corollary 10 = e 3v – 6 = 15 – 6 = 9.
This is a contradiction. So K5 is not planar.
Copyright M.R.K. Krishna Rao 2003
112
Euler Theorem – Corollary 2
Corollary 1 is not useful in proving that K3,3 is not
planar as 9 = e 3v – 6 = 18 – 6 = 12.
The following corollary can do it.
Corollary 2: If G is a connected planar simple graph
with e edges and v 3 vertices and have no
circuits of length 3, then e 2v – 4.
Proof: Similar to corollary 1, 2e = fR deg(f) 4r.
Hence e/2 r. Using Euler’s formula, we get
e – v + 2 e/2 and e/2 v – 2. Therefore, e 2v – 4.
Example: Prove that K3,3 is not planar.
Proof: Suppose K3,3 is planar. Then by the
Above corollary 9 = e 2v – 4 = 12 – 4 = 8.
This is a contradiction. So K3,3 is not planar.
Copyright M.R.K. Krishna Rao 2003
113
Proving that Q4 is Non-Planar
Now we have enough techniques to prove
that the 4-cube is non-planar.
Count the number of vertices and edges:
|V | = 16 (twice the number for 3-cube)
|E | = 32 (twice the number for 3-cube
plus number of vertices in 3-cube)
Can we use corollary 1 -- is e 3v – 6 ?
NO, 32= e 3v – 6 = 3*16 – 6 = 42
Can we use corollary 2 -- is e 2v – 4 ?
YES, 32= e 2v – 4 = 2*16 – 4 = 28
114
Copyright M.R.K. Krishna Rao 2003
Homeomorphism
An elementary subdivision is an operation to
replace an edge {u,v} in a graph by two edges
{u,w} and {w,v}, where w is a newly introduced
vertex.
Two graphs G1 and G2 are homeomorphic if they
can be obtained by a sequence of elementary
subdivisions from the same graph.
115
Copyright M.R.K. Krishna Rao 2003
Kuratowski's Theorem
Kuratowski's Theorem: A graph is nonplanar if
and only if it contains a subgraph
homeomorphic to K3,3 or K5.
Examples:
116
Copyright M.R.K. Krishna Rao 2003
7.8 - Graph Coloring
Consider a fictional continent.
117
Copyright M.R.K. Krishna Rao 2003
Map Coloring
Suppose removed all borders but still wanted
to see all the countries. 1 color
insufficient.
118
Copyright M.R.K. Krishna Rao 2003
Map Coloring
So add another color. Try to fill in every
country with one of the two colors.
119
Copyright M.R.K. Krishna Rao 2003
Map Coloring
Try to fill in every country with one of the
two colors.
120
Copyright M.R.K. Krishna Rao 2003
Map Coloring
Try to fill in every country with one of the
two colors.
121
Copyright M.R.K. Krishna Rao 2003
Map Coloring
Try to fill in every country with one of the
two colors.
122
Copyright M.R.K. Krishna Rao 2003
Map Coloring
PROBLEM: Two adjacent countries forced to
have same color. Border unseen.
123
Copyright M.R.K. Krishna Rao 2003
Map Coloring
So add another color:
124
Copyright M.R.K. Krishna Rao 2003
Map Coloring
Insufficient. Need 4 colors because of
this country.
125
Copyright M.R.K. Krishna Rao 2003
Map Coloring
With 4 colors, could do it.
126
Copyright M.R.K. Krishna Rao 2003
4-Color Theorem
Theorem: Any planar map of regions can be
depicted using 4 colors so that no two
regions that share a positive-length border
have the same color.
Proof by Haaken and Appel used exhaustive
computer search.
127
Copyright M.R.K. Krishna Rao 2003
From Map Coloring
to Graph Coloring
The problem of coloring a map, can be
reduced to a graph-theoretic problem:
128
Copyright M.R.K. Krishna Rao 2003
From Map Coloring
to Graph Coloring
For each region introduce a vertex:
129
Copyright M.R.K. Krishna Rao 2003
From Map Coloring
to Graph Coloring
For each pair of regions with a positivelength common border introduce an edge:
130
Copyright M.R.K. Krishna Rao 2003
From Map Coloring
to Graph Coloring
Coloring regions is equivalent to
coloring vertices of the dual graph.
131
Copyright M.R.K. Krishna Rao 2003
Definition of Colorable
DEF: Let n be a positive number. A simple graph is n colorable if the vertices can be colored using n
colors so that no two adjacent vertices have the
same color.
The chromatic number of a graph is smallest number
n for which it is n -colorable.
132
Copyright M.R.K. Krishna Rao 2003
Chromatic numbers
Theorem: A graph is bipartite iff it is 2-colorable.
Theorem Chromatic number of complete graph Kn is n.
Theorem: The chromatic number of the graph Cn is
2, when n is even;
3, when n is odd and n > 1.
The four-color theorem: The chromatic
number of a planar graph is no greater
than four.
133
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
Example: Suppose want to schedule some final
exams for CS courses with following numbers:
1007, 3137, 3157, 3203, 3261, 4115, 4118, 4156
Suppose also that there are no common students in
the following pairs of courses because of
prerequisites:
1007-3137
1007-3157, 3137-3157
1007-3203
1007-3261, 3137-3261, 3203-3261
1007-4115, 3137-4115, 3203-4115, 3261-4115
1007-4118, 3137-4118
1007-4156, 3137-4156, 3157-4156
How many exam slots are necessary to schedule
their exams?
134
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and
Schedules
Turn this into a graph coloring problem.
Vertices are courses, and edges are courses
which cannot be scheduled simultaneously
because of possible students in common:
3203
3261
3137
4115
1007
4118
3157
4156
135
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and
Schedules
One way to do this is to put edges down where
students mutually excluded…
3203
3261
3137
4115
1007
4118
3157
4156
136
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and
Schedules
…and then compute the complementary
graph:
3203
3261
3137
4115
1007
4118
3157
4156
137
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and
Schedules
Redraw:
3137
1007
3203
3261
4115
3157
4156
4118
138
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and
Schedules
Not 1-colorable because of edge
3137
1007
3203
3261
4115
3157
4156
4118
139
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and
Schedules
Not 2-colorable because of triangle
3137
1007
3203
3261
4115
3157
4156
4118
140
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
Is it 3-colorable? Try to color by Red,
Green, Black.
3137
1007
3203
3261
4115
3157
4156
4118
141
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
WLOG. 3203-Red, 3157-Black, 4118Green:
3137
1007
3203
3261
4115
3157
4156
4118
142
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
So 4156 must be Black:
3137
1007
3203
3261
4115
3157
4156
4118
143
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
So 3261 and 4115 must be Red.
3137
1007
3203
3261
4115
3157
4156
4118
144
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
3137 and 1007 easy to color.
3137
1007
3203
3261
4115
3157
4156
4118
145
Copyright M.R.K. Krishna Rao 2003
Graph Coloring and Schedules
So need 3 exam slots:
3137
3203
Slot 1
1007
Slot 2
3261
4115
3157
4156
4118
Slot 3
146
Copyright M.R.K. Krishna Rao 2003
© Copyright 2026 Paperzz