You are on page 1of 55

1

Discrete Mathematics and


Statistics
Graphs and Trees
2

Introduction

Because many situations and structures give rise to
graphs, graph theory has become an important
mathematical tool in a wide variety of subjects,
ranging from operations research, computing
science and linguistics to chemistry and genetics.


Recently, there has been considerable interest in tree
structures arising in computer science and artificial
intelligence. We often organize data in a computer
memory store or the flow of information through a
system in tree structure form. Indeed, many
computer operating systems are designed to be tree
structures.


3
What is a Graph
P Q
T
S
R
electrical network
P Q
R
S T
road map
P
Q
R
S T
Diagrammatic Representation
4
Undirected Graph
An undirected graph G consists of a non-empty
set of elements, called vertices,
and a set of edges, where each edge is associated
with a list of unordered pairs of either one or two
vertices called its endpoints. The correspondence
from edges to end-points is called an edge-
endpoint function.
5
Edge e
1
e
2
e
3
e
4

Endpoints {u, v} {u, w} {v, w} {w, z}

Example 1 (Undirected Graph)
u
v w
z
e
1

e
2

e
3

e
4

vertex-set V(G) = {u, v, w, z}
edge-set E(G) = {e
1
, e
2
, e
3
, e
4
}
edge-endpoint function
6
Directed Graph
A directed graph G consists of vertices, and a set
of edges, where each edge is associated with a list
of ordered pair endpoints
7
Edge e
1
e
2
e
3
e
4

Endpoints (u, v) (w, u) (w, v) (z, w)

Example 2 (Directed Graph)
vertex-set V(G) = {u, v, w, z}
edge-set E(G) = {e
1
, e
2
, e
3
, e
4
}
edge-endpoint function
u
v w
z
e
1

e
2

e
3

e
4

8
Multiple edges , Loop and Degree
Two or more edges joining the same pair of
vertices are called multiple edges
and an edge joining a vertex to itself is called a
loop.
The degree of a vertex is the number of edges
meeting at a given vertex.
9
Example 3 (Multiple edges , Loop and Degree)
V(G) = {u, v, w, z}
E(G) = {e
1
, e
2
, e
3
, e
4
, e
5
, e
6
, e
7
}
edge-endpoint function
u
v
w
z
Multiple
edges
loop
e
1
e
2
e
3
e
4

e
5
e
6
e
7
deg u = 6, deg v = 5,
deg w = 2, deg z = 1
total degree = 6 + 5 + 2 + 1 = 14
Edge e
1
e
2
e
3
e
4
e
5
e
6
e
7

Edge points {u, u} {u, w} {v, w} {v, z} {u, v} {u, v} {u, v}

10
Connected and Disconnected Graphs

A graph G is
connected if there is a
path in G between any
given pair of vertices,
and disconnected
otherwise.
Connected Graph
Disconnected Graph
components
11
Complete graph

K
2

K
3

K
4

K
5

V
1
V
2

V
1

V
2

V
3

V
1

V
2

V
3

V
4

V
1

V
2

V
3

V
4
V
5

A complete graph on n vertices , denoted K
n
, is a
simple graph with n vertices v
1
, v
2
, v
n
whose
set of edges contains exactly one edge for each
pair of distinct vertices.
12
The Handshaking Lemma
In any graph, the sum of all the vertex-degrees is equal to
twice the number of edges.(see e.g.3)
No. of edges =7
total degree = 6 + 5 + 2 + 1 = 14
As the consequences of the Handshaking Lemma,
the sum of all the vertex-degrees is an even
number and the number of vertices of odd degree
is even.(e.g. 3 odd deg vertices are:v and z)
13
Matrix Representations of Undirected Graph
|
|
|
|
|
.
|

\
|
0 1 2 2
1 0 1 0
2 1 0 1
2 0 1 0 v
1


v
2


v
3


v
4

v
1
v
2
v
3
v
4

A(G) =
v
1

v
2

v
3

v
4

Adjacency Matrix A(G)
14
Matrix Representations of Undirected Graph
Incidence Matrix I(G)
v
1

v
2

v
3

v
4

e
1

e
2

e
3

e
4
e
5

e
6

e
7

|
|
|
|
|
.
|

\
|
1 1 1 1 1 0 0
0 0 0 0 1 1 0
1 1 0 0 0 1 1
0 0 1 1 0 0 1
e
1
e
2
e
3
e
4
e
5
e
6
e
7

v
1


v
2


v
3


v
4

I(G) =
15
Matrix Representations of Directed Graph
Adjacency Matrix A(G)
v
1

V
2

V
3

e
1

e
2

e
3

e
4

e
5

|
|
|
.
|

\
|
1 0 0
2 0 1
0 1 0
v
1


v
2


v
3


v
1
v
2
v
3

A(G) =
16
Matrix Representations of Directed Graph
Incidence Matrix I(G)
v
1

V
2

V
3

e
1

e
2

e
3

e
4

e
5

v
1


v
2


v
3


e
1
e
2
e
3
e
4
e
5
I(G) =
|
|
|
.
|

\
|

+ + +
+
2 1 1 0 0
0 1 1 1 1
0 0 0 1 1
17
Walk
A walk of length k between v
1
and v
8
in a graph G is a
succession of k edges of G of the form v
1
e
1
v
2
, v
2
e
2
v
3
, v
3
e
3
v
4
,
,v
7
e
7
v
8
.
We denote this walk by v
1
e
1
v
2
e
2
v
3
e
3
v
4
e
4
v
5
e
5
v
6
e
6
v
7
e
7
v
8
.
v
1

v
2

v
3

v
4

v
5

v
6

v
7

e
1
e
2
e
3
e
4
e
5
e
6
e
7
v
8

18
Paths and circuits
If all the edges (but not necessarily all the
vertices) of a walk are different, then the walk is
called a path.
If , in addition, all the vertices are different, then
the trail is called simple path.
A closed path is called a circuit.
A simple circuit is a circuit that does not have any
other repeated vertex except the first and last.
19
Example (Paths)
v
1

v
3

v
5

v
4

v
2

path
v
1

v
3

v
5

v
4

v
2

simple
path
v
1
v
2
v
4
v
1
v
3
v
5
is a path v
1
v
2
v
4
v
3
v
5
is a simple path
20
Example (circuits)
v
1

v
3

v
5

v
4

v
2

circuit
v
1

v
3

v
5

v
4

v
2

simple
circuit
v
1
v
2
v
4
v
3
v
5
v
4
v
1
is a circuit v
1
v
2
v
4
v
5
v
3
v
1
is a simple circuit
21
Summarized Table
Repeated Edge Repeated Vertex Starts and Ends
at Same Point
Walk
Path
Simple path
Closed walk
Circuit
Simple circuit
Allowed
No
No
Allowed
No
No
Allowed
Allowed
No
Allowed
Allowed
First and last
only
Allowed
Allowed
No
Yes
Yes
Yes
22
Counting Walks of Length N
If G is a graph with vertices v
1
, v
2
, v
m

and A(G) is the adjacency matrix of G, then
for each positive integer n,

the ijth entry of A
n
= the number of
walks of length n from
v
i
to v
j
.

23
Example (Counting Walks)
(
(
(

=
0 2 0
2 1 1
0 1 0
A
v
1

v
2

v
3

e
1
e
2
e
3
e
4
Adjacency matrix A(G)
24
Example (cont.)
(
(
(

=
4 2 2
2 6 1
2 1 1
A
2
one walk of length 2
connecting v
1
to v
1

(v
1
e
1
v
2
e
1
v
1
)

two walks of length 2
connecting v
1
to v
3

(v
1
e
1
v
2
e
3
v
3
,
v
1
e
1
v
2
e
4
v
3
)

25
The Shortest Path Algorithm
The objective of this algorithm is to find the
shortest path from vertex S to vertex T in a given
network.
We demonstrate the steps of the algorithm by
finding the shortest distance from S to T in the
following network:
26
Example (Shortest Path Alg.)
7
4
9
7
1
3
1
6
3
4
S
A
T
B
C
D
27
Example (Cont.)
7
4
9
7
1
3
1
6
3
4
S
A
T
B
C
D
0
7
4
9
7
28
Example (cont.)
7
4
9
7
1
3
1
6
3
4
S
A
T
B
C
D
0
5
4
7
7
29
Example (cont.)
7
4
9
7
1
3
1
6
3
4
S
A
T
B
C
D
0
5
4
7
7
11
30
Example (cont.)
7
4
9
7
1
3
1
6
3
4
S
A
T
B
C
D
0
5
4
7
7
10
31
Example (Cont.)
7
4
9
7
1
3
1
6
3
4
S
A
T
B
C
D
0
5
4
7
7
10
Therefore, the shortest path from S to T is SBCT with path length 10
32
Eulerian Graphs
A connected graph G is Eulerian if there is a closed path
which includes every edge of G; such a path is called an
Eulerian path
1
2
3
4
5
6
7
8
p
q
r
s
t
33
Theorem (Eulerian Graph)
Let G be a connected graph. Then G is Eulerian if
and only if every vertex of G has even degree.
Which of the following graph(s) is/are Eulerian?
(a) (b) (c)
(d)
34
Knigsberg bridges problem
The four places (A, B, C and D) in the city of Knigsberg were
interconnected by seven bridges (p, q, r, s, t, u and v) as shown
in the following diagram. Is it possible to find a route crossing
each bridge exactly once ?
Knigsberg
A
B
C
D
p
q
r
s
t
u
v
35
Answer (Knigsberg bridges problem)
By the theorem, it is not a Eulerian graph. It follows that there is no
route of the desired kind crossing the seven bridges of Knigsberg.
We can express the Knigsberg bridges problem in terms of a graph by
taking the four land areas as vertices and the seven bridges as edges
joining the corresponding pairs of vertices.
C
A
B
D
p
r
s
q
t
u
v
36
Fleurys Algorithm
STEP 1 Choose a starting vertex u.
STEP 2 At each stage, traverse any available edge,
choosing a bridge only if there is no
alternative.
STEP 3 After traversing each edge, erase it ( erasing
any vertices of degree 0 which result),
and then choose another available edge.
STEP 4 STOP when there are no more edges.

37
Example (Fleurys Algorithm)
Find the Eulerian path of the following graph.
b
f
a c
d
e
u
38
Example (cont.)
Starting at u, we may
choose the edge ua,
followed by ab.
Erasing these edges
and the vertex a give
us graph (b)
b
f
a c
d
e
u
(a)
39
Example (cont.)
We cannot use the
edge bu since it is a
bridge, so we choose
the edge bc, followed
by cd and db. Erasing
these edges and the
vertices c and d give
us graph (c)

b
f
c
d
e
u
(b)
40
Example (cont.)
We have to traverse
the bridge bu.
Traversing the cycle
uefu completes the
Eulerian path. The
path is therefore
uabcdbuefu.
b
f
e
u
(c)
41
Hamiltonian Graphs
A connected graph G is Hamiltonian if there is a
cycle which includes every vertex of G ; such a
cycle is called a Hamiltonian cycle.
p q
r s
t
p q
Hamiltonian Graph
r s
t
Hamiltonian Cycle
42
DIRACS THEOREM
Let G be a simple graph with n vertices, where n >
3. If deg v > n/2 for each vertex v, then G is
Hamiltonian.
For the above graph, n = 6 and deg v = 3 for each
vertex v, so this graph is Hamitonian by Diracs
theorem.
43
ORES THEOREM
Let G be a simple graph with n vertices, where n > 3.

If deg v + deg w > n,

for each pair of non-adjacent vertices v and w, then
G is Hamiltonian.
44
Example (Ores Thm)
n = 5 but deg u = 2, so
Diracs theorem does
not apply.
However, deg v + deg
w > 5 for all pairs of
non-adjacent vertices
v and w, so this graph
is Hamiltonian by
Ores theorem.
u
45
Trees
A tree is a connected graph which contains no
cycles.
Properties of Tree
Every tree with n vertices has exactly n 1 edges.
Any two vertices in a tree are connected by exactly
one path.
Each edge of a tree is a bridge.
46
Alternative definitions of the tree
T is connected and has n 1 edges.
T has n 1 edges and contains no cycles.
T is connected and each edge is a bridge.
Any two vertices of T are connected by
exactly one path.
47
Spanning Trees
Let G be a connected graph. A spanning tree in G
is a subgraph of G that includes all the vertices of
G and is also a tree. The edges of the tree are
called branches.

48
Example (Spanning Trees)
v w
x
y
z
v w
x
y
z
v w
x
y
z
v w
x
y
z
A graph G
Spanning Trees
49
Minimum Spanning Tree
Let T be a spanning tree of minimum total
weight in a connected weighted graph G.
Then T is a minimum spanning tree of G.
50
Greedy Algorithm
Illustrated Example
A
C
B
D
E
2
6
7
5
9
6
4
8 5
8
51
Greedy Algorithm (cont.)
Iteration 1 (Choose an edge of minimum weight)
A
C
B
D
E
2
6
7
5
9
6
4
8 5
8
52
Greedy Algorithm (cont.)
Iteration 2 (Select the vertex from unconnected set
{A,B,C} that is closest to connected set {D,E})
A
C
B
D
E
2
6
7
5
9
6
4
8 5
8
53
Greedy Algorithm (cont.)
Iteration 3 (Select the vertex from unconnected set
{A,C} that is closest to connected set {B,D,E,})
A
C
B
D
E
2
6
7
5
9
6
4
8
8
54
Greedy Algorithm (cont.)
Iteration 4 (Select the vertex from unconnected set
{C} that is closest to connected set {A,B,D,E})
A
C
B
D
E
2
7
5
9
4
8
8
55
Greedy Algorithm (cont.)
Therefore, the minimum spanning tree is with
weight 18.
A
C
B
D
E
2
7
5
4

You might also like