Graphs - Discrete Mathematics
Graphs - Discrete Mathematics
Graphs - Discrete Mathematics
GRAPHS
Def
A graph G = (V, E) consists of a finite set V of vertices and a set E of
edges, such that each edge e E is associated with an unordered pair of
vertices. We write e = {v, w} = {w, v}. We assume v 6= w. We say v, w V
are adjacent vertices and that e is incident on v and w.
Ex.
V = {1, 3, 5, 7, 9} E = {{3, 7}, {5, 1}, {5, 9}, {1, 9}, {3, 5}}
Graphically:
3 5
7 9
K1 K2
K3 K4
Def. Subgraphs.
A graph G2 = (V2 , E2 ) is a subgraph of a graph G1 = (V1 , E1 ) iff V2 V1
and E2 E1 . If the edges of G1 connecting vertices of G2 are all in G2 , we say
G2 is a complete subgraph of G1 :
{x, y} E1 , x, y V2 = {x, y} E2
1
Ex.
1 1 1
0 2 0 2 0 2
4 3 3 3
G1 G2 G3
Graph Representations
Two of the most common ways of representing graphs is as an adjacency list,
which consists of a list of vertices, where each vertex vi stores a list of all its
adjacent vertices vj .
Ex.
1
0 2
4 3
G1
0 1 2 3 4
1 0 2
The adjacent vertices to vertex 2 are vertices 0, 1 and 3.
2 0 1 3
3 0 2 4
4 3 0
2
0 1 2 3 4
0 0 1 1 1 1
1 1
0 1 0 0
2 1
1 0 1 0 is the adjacency matrix of graph G1 . It is symmetric.
3 1 0 1 0 1
4 1 0 0 1 0
Theorem
The sum of the degrees of the vertices of a graph is twice the number of its
edges. X
deg(v) = 2 |E(G)|
vV (G)
Proof
Each edge contributes 2 to the degree sum.
Corollary
The number of vertices with an odd degree must be even.
Ex.
1
5 2
4 3
G1
Ex.
A certain company wants to build a network with its 5 computers, joining each
one to exactly three others. Is this possible?
The cities of a certain country are all connected to exactly three other cities.
Can this country have 50 roads? If they tell us it has 60 roads, how many cities
are there?
Can you draw 9 segments on a sheet of paper such that each one cuts exactly
three of the other segments? If you want to draw 6?
Def.
A graph is regular of degree r if every vertex has degree r.
3
Ex.
Kn is regular of degree n 1.
Def.
Two graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are called isomorphic, written
G1 G2 , or that there is an isomrphism of one onto the other, if there
exists a bijection b : V1 V2 such that
a b
a b a c b d
c d c a d b
c d
G1 is isomorphic to G2 b() = = a, b, c, d, a , b , c , d is an
isomorphism.
It is not always easy to determine if two graphs are isomorphic, but if
Proposition
4
Ex.
G1 6 G2
a 1
e b 0 2
d c 4 3
G1 G2
K4 is a subgraph of G1 .
K4 is not a subgraph of G2 .
1 2
G1 G2
Def.
Let G = (V, E) be a graph.
A walk in G is a sequence of vertices v0 , . . . , vn such that vi and vi+1 are
adjacent for 0 i n 1. If all vertices are distinct, a walk is called a path.
We say the walk visits vertices vi (0 i n) and that {vi , vi+1 } are the edges
of the walk. If n is the number of edges, n is the length of the walk.
A circuit in G is a walk v0 , . . . , vn such that v0 = vn .
5
A cycle in G is a path v0 , . . . , vn such that v0 = vn . If n = 0 or n = 2 we call
it a trivial path.
Ex.
f d
g c
e
a b
ui1 uj+1 un = y
ui = uj
u0 = x
6
ui1 uj+1 un = y
ui = uj
u0 = x
Def.
Let G = (V, E) be a graph. We define a relation C as follows:
Lemma 2
C is an equivalence relation.
Proof
C is clearly reflexive and symmetric. Let us show it is also transitive.
x, y, z V, xCy, yCz = xCz
There is a path x = v0 , v1 , . . . , vn = y joining x and y and there is another
path y = u0 , u1 , . . . , um = z joining y and z. Hence, there is a walk (there
may be vertices repeated) joining x and z, namely x = v0 , v1 , . . . , vn = y =
u0 , . . . , um = z. By Lemma 1 there is a path joining x and z, that is xCz.
Def.
Let G = (V, E) be a graph and let x V . The equivalence class of x, [x]C ,
determined by C
[x]C = {y V |xCy}
is called the connected component of x. The complete subgraph (vertices
+ edges) given by this equivalence class is also called the connected com-
ponent of x.
Ex.
a b f h
e j i
d c g
This graph has three connected components: [a] = {a, b, c, d} [e] = {e, f, g}
[h] = {h, i, j}.
Def.
If a graph G = (V, E) has just one connected component it is said to be
connected.
Any two vertices of a connected graph are joined by a path.
7
If a graph is connected there is a walk v0 , . . . , vn that visits each vertex of G.
If a graph G = (V, E) is connected, if |V | = n it must have at least n 1
edges.
Ex.
2 3
0
1 4
6 5
Def.
A cut vertex of a graph G = (V, E) is a vertex v V such that its re-
moval and all edges incident with it produces a subgraph with more connected
components than G.
Ex.
=
a
Def.
A tree is a connected graph with no cycles.
Def.
A rooted tree is a tree T in which one vertex x0 , called the root, is distin-
guished in some way.
f g a c
d b b a
c
d e
b
a e f g e d
With root a g
c f
With root c
8
Hamiltonian Graphs.
Def.
A Hamiltonian cycle or Hamilton cycle is a cycle that visits every vertex
of a graph. We say a graph is a Hamiltonian graph if it contains a Hamilton
cycle.
1 2 a d
b c
d
4 3 a
b c
K4 Q3 (A cube)
1, 2, 3, 4, 1 a, b, c, d, d, c , b , a , a
Hamilton cycles.
G must be connected.
G cannot have vertices of degree 1 and every vertex is of degree 2
G cannot have cut vertices
9
Sufficient Conditions for a graph to be Hamiltonian.
Theorem(Dirac)
n
Let G = (V, E) be a connected graph with n = |V | 3. If v V deg(v)
2
then G is Hamiltonian.
Diracs theorem is a consequence of Ores theorem.
Theorem(Ore)
Let G = (V, E) be a connected graph with n = |V | 3. If deg(u) + deg(v) n
for every pair of non-adjacent vertices u and v of G, then G is Hamiltonian.
Proof
If n = 3 the only graph satisfying the assumption is K3 . It is Hamiltonian.
Let n 4 and suppose G verifies the hypothesis but it is not Hamiltonian. If
we add edges to the graph, the assumption will still hold. Add edges to G until
we reach the graph G = (V, E ) such that it is not Hamiltonian, but addition
of any new edge would give a Hamiltonian graph.
Let e = {u, w} V V be an edge 6 E . G {e} has a Hamiltonian cycle:
u = v0 , v1 , v2 , . . . , vn1 = w, u (using e)
We now consider walk P : u = v0 , v1 , v2 , . . . , vn1 = w length = n 1 and
v V v P
Let
Eu = {{vi , vi+1 }|{u, vi+1} E}
Ew = {{vi , vi+1 }|{vi, w} E}
Using the assumption of the theorem, we get |Eu | + |Ew | n thus, there is an
edge {vi , vi+1 } Eu Ew . i 6= 0 and i 6= n 2, since {u, w} 6 E.
u v1 v2 vi vi+1 vn2 w
This is a Hamiltonian graph but does not verify the hypothesis of diracs and
Ores theorems.
10
Multigraphs.
Sometimes vertices can be connected by more than one edge. This situation
gives rise to the concept of multigraphs. Graphs are a particular case of multi-
graphs.
Def.
A multigraph G = (V, E, I) consists of a set V of vertices, a set E of edges
and an incidence relation I V E V such that:
Ex.
e1
1 2
e2
e3 e4
V = {1, 2, 3} E = {e1 , e2 , e3 , e4 } I = {(1, e1, 2), (1, e2 , 2), (1, e3, 3), (2, e4, 3)}
deg(1) = deg(2) = 3 deg(3) = 2.
Def.
We are now going to study walks which use each edge of a graph exactly once.
Euler was the first to study such walks.
11
Def.
Let G = (V, E, I) be a multigraph.
An Eulerian or Euler circuit is a circuit containing every edge of G exactly
once.
An Eulerian or Euler walk is a walk containing every edge of G exactly
once.
We say a multigraph is Eulerian if it contains an Euler circuit and we say it
is semi-Eulerian if it contains an Euler walk.
Every Eulerian graph is semi-Eulerian.
It is much more difficult to determine if a graph is Hamiltonian rather than
Eulerian.
Theorem
Let G = (V, E, I) be a connected multigraph.
Proof
We prove (2) assuming (1) is true.
=)
Let R : u = x0 , e1 , x1 , . . . , xn1 , en , xn = v be an Euler walk in G.
If u = v, R is a circuit, G is Eulerian and by (1) every vertex has even degree.
If u 6= v, if we add an edge e joining u with v we obtain an Eulerian multigraph
G and by (1) all vertices of G have even degree. Hence, all vertices of G, except
u, v have even degree.
=)
If every vertex has even degree, G is Eulerian by (1).
If G has exactly two vertices of odd degree u, v, if we add an edge e connecting
u with v, we obtain a multigraph G such that all vertices are of even degree.
By (1), G has an Euler circuit C. Without loss of generality we may suppose
C is v, e, u, . . . , v. If we delete edge e, we obtain an Euler walk from u to v.
Hence G is semi-Eulerian.
Proof of (1).
=)
Suppose G has an Euler circuit. It begins with a vertex a and continues with
an edge incident to a, say e. This edge contributes 1 to deg(a). Each time the
circuit passes through a vertex it contributes 2 to the vertexs degree since
the circuit enters via an edge incident with this vertex and leaves via another
such edge. Finally the circuit terminates where it started, contributing 1 to
deg(a). Therefore deg(a) must be even and vertices other than a, also must
12
have even degree because the circuit contributes 2 to its degree each time it
passes through the vertex.
=)
The proof is by induction on the number of edges n in G.
Basis step (n = 0).
Since G is connected, if G has no edges G has a single vertex. An Euler circuit
consists of the single vertex and no edges.
Inductive Step.
Suppose that G has n edges, n > 0 and that any connected graph with k
edges, k < n, in which every vertex has even degree, has an Euler circuit.
We will form a circuit that begins at an arbitrary vertex a V . First, we
arbitrarily choose an edge e1 incident with a. We continue by building a walk
a = v0 , e1 , v1 , . . . , vn1 , en , vn that is as long as possible.
v4
5 4
v6 6 v2
v3
3
7 2
1 v1
a
a, 1, v1, 2, v2 , 3, v3 , 4, v4 , 5, v2 , 6, v6, 7, a
The walk terminates, since the graph has a finite number of edges. It begins
at a with an edge e1 and finishes at a with an edge en , (vn = a). This follows
because each time the walk goes through a vertex with even degree, it uses
only one edge to enter this vertex, so that at least one edge remains for the
walk to leave the vertex. This circuit may use all the edges or it may not.
An Euler circuit has been constructed if all the edges have been used. Other-
wise consider subgraph H obtained from G by deleting the edges already used
and vertices that are not incident with any remaining edges.
Since G is connected, H has at least one vertex in common with the circuit
that has been deleted. Let w be such a vertex.
Every vertex in H has even degree (because in G all vertices had even degree
and for each vertex, pairs of edges incident with this vertex have been deleted
to form H.)
H may not be connected. Let H1 , . . . , Hk be the connected components of H.
Each Hi 1 i k has less edges than G. By the inductive hypothesis we
can obtain Euler circuits Ci for each Hi . Since, there is at least a vertex wi
common to C and each Ci , we may combine C, C1, . . . Ck to obtain an Euler
circuit in G.
13
2 1
3 w1
w2 1
4 2
C1 : 1 , 2 , 3 C2 : 1 , 2 , 3, 4
v4
C1 5 4
v6 6 v2
v3
3
7 2
1 v1
a
C2
a, 1, v1 = w2 , C2 (1 , 2 , 3 , 4 ), w2 = v1 , 2, v2, 3, v3 , 4, v4 , 5, v2 , 6, v6 = w1 , C1 (1 , 2 , 3),
w1 = v6 , 7, a
Euler proved that it was not possible to start at some location in the town,
travel across every bridge without crossing any bridge more than once and
returning to the starting point.
There is no Euler walk or circuit in this multigraph. (1 vertex of degree 5 and
3 vertices of degree 3).
14
Ex.
4 3
2
5
8
1 7
9
6
a 10 b
DIGRAPHS
Def.
A digraph (or directed graph) G = (V, A) consists of a finite set V of vertices
and a relation A V V called adjacency relation.
If (x, y) A we say (x, y) is an arc. (Arcs are ordered pairs (v, w) whereas
edges are unordered pairs {v, w}).
An arc (v, v) is said to be a loop.
Ex.
a b c
f
e
d
The definitions of walk, path, circuit and cycle carry over from graphs to
digraphs in an obvious way.
Def.
Let G = (V, A) be a directed graph.
15
Representation of Directed Graphs
We may represent directed digraphs by means of adjacency lists and adja-
cency matrices.
Ex.
a b c 1 2
f
e
d 4 3
D1 D2
a
b c 1 1 2
c 2
d c b 3 2 4
e a d e f 4 1 3
f
D1 D2
a b c d e f
a 0 0 0 0 0 0
b 0 0 1 0 0 0 1 2 3 4
0
1 1 1 0 0
c 0 0 0 0 0
0
2 0 0 0 0
d 1 1 0 0 0
1
3 0 1 0 1
e 0 0 1 1 1
4 1 0 1 0
f 0 0 0 0 0 0
16
Def.
(V1 , A1 ) (V2 , A2 ) are isomorphic digraphs if there exists a bijection :
V1 V2 such that
x, y V1 , xA1 y (x)A2 (y)
Theorem
Let G = (V, A) be a directed graph.
X X
+ (v) = |A| = (v)
vV (G) vV (G)
Ex.
a b
e
+ (a) + + (b) + + (c) + + (d) + + (e) = 2 + 2 + 0 + 1 + 1 = 6
Connected Digraphs
Def.
Let D = (V, A) be a digraph. Let x, y V . We say
y is accesible from x there is a path from x to y.
(In general this is not an equivalence relation.)
We say D = (V, A) is a connected digraph if there exists a vertex x0 such
that each y V is accesible from x0 .
Ex.
17