You are on page 1of 25

Lecture #9 Graphs and Trees

Topics
1. Graphs
1.1. Types of Graphs
1.2. Basis of Graphs
1.3. Bipartite Graphs
1.4. Graphs as Matrices
1.5. Isomorphisms
1.6. Connectivity
1.7. Euler Paths
1.8. Hamilton Paths
1.9. Planar Graphs
2. Trees (Brie y)
2.1. Basis
2.2. Spanning Trees

1 Graphs
 Graphs are discrete structures consisting of vertices and edges that connect these vertices.
|-> Figure ( g. 1 p. 430)

 Problems in many disciplines can be solved using graph models.


 In the above gure, each vertex represents a computer in a city, and each
edge represents a telephone line between two cities.

1.1 Types of Graphs

 The rst type of graphs that we consider is called a simple graph.


 In a simple graph, each edge connects two distinct vertices and no two
edges connect the same pair of vertices.

De nition 1.1

Simple Graphs

simple

graph

= (V ,E ) consists of

, a nonempty set of vertices, and

, a set of unordered pairs of distinct elements of V called edges.

 Thus, simple graphs have no direction.


 Sometimes, we want to model a kind of telephone networks which have
multiple telephone lines between computers.
|-> Figure ( g. 2. p. 430)

 Simple graphs are not sucient to model such networks.


2

 In this situation, we need a multi-graph which allows multiple edges between the same pairs of vertices.

De nition 1.2

Multigraph

1. A multigraph

= (V ,E ) consists of a set V of vertices, a set E of edges,

and a function f from E to ffu,vg j u, v

, u 6= v g.

2. The edges e1 and e2 are called multiple edges if f (e1) = f (e2).

We cannot use a pair of vertices to specify an edge of a graph when

multiple edges are present. Why ???? (Tutorial)

 Every simple graph is also a multigraph.

However, not all multigraphs

are simple graphs.

 However, multigraphs do not allow an edge which links a vertex to itself,


ie. a loop.
|-> Figure ( g. 3. p. 431)

 A kind of multigraphs which allows a loop is called Pseudographs.


De nition 1.3

Pseudograph

1) A pseudograph G = (V ,E ) consists of a set V of vertices, a set E of edges,


and a function f from E to ffu,vg j u, v
2) An edge is a loop if f

2 g.
( ) = f g for some 2
e

 We shall use the set f , g and the edge


u v

interchangeably, unless the

identity of individual multiple edges is important.

 Sometimes, we want to specify directions

of edges, for example to tell

directions of a connection line between two computers.


3

|-> Figure ( g. 4 p. 432)

 We need directed graphs to model such kinds of networks.


 Such a directed edge is represented by an ordered pair of vertices.
De nition 1.4
A directed

Directed Graphs

(V ,E ) consists of a set of vertices V and a set of edges E

graph

that are ordered pairs of elements of V , ie.


E

= f (v1,

v2)

j v1, v2 2

and v1

6= v2 g.

 Note that this de nition of directed graphs allows a loop but does not
allow multiple edges.

De nition 1.5
A directed

Directed Multigraphs

multigraph

= (V ,E ) consists of a set V of vertices, a set E of

edges, and a function f from E to f(u,v) j u,v

2 g.
V

 We shall use the term graph to describe graphs with directed or undirected
edges, with or without loops and multiple edges.

 We shall use the terms undirected graph or pseudograph for an undirected


graph that may have multiple edges or loops.

1.2 Graph Models

 We shall discuss the use of graphs to model problems in Computer applications.

 In particular, we discuss brie y the use of precedence graphs for concurrent


processing.
4

 Consider the following commands.


|-> Figure ( g. 9. p. 435)

 Each statement is represented by a vertex.


 There is an edge from one vertex to a second vertex if the statement
represented by the second vertex cannot be executed before the statement
represented by the rst vertex has been executed.

 Such graph is called precedence graph.


 The precedence graph helps us to analyse and to determine which statements can be executed in parallel.

1.3 Graph Terminology

 Before we study properties of graphs, we need to understand some basic


terminology of a graph.

De nition 1.6

Adjacent Vertices and Incident Edges

1) Two vertices u and v in an undirected graph G are called adjacent in G


if fu,vg is an edge of G.

2) If e = fu,vg, the edge e is called incident with the vertices u and v.


3) The edge e is also said to connect

and v.

4) The vertices u and v are called endpoints of the edge fu,vg.

 The following de nition is used

to keep track of how many edges are

incident to a vertex.

De nition 1.7
The degree

Degree

deg(v)

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.

Example 1.1

Degree

|-> Figure ( g. 1. p. 438)

 In

deg(a)

= 2,

deg(b)

deg(c)

deg(f )

= 4,

deg(d)

= 1,

deg(e)

=3

and deg(g) = 0.

 In

, deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1 and deg(d) = 5.

 A vertex of degree 0 is called isolated.


 It follows that an isolated vertex is not adjacent to any vertex.
 Vertex in graph in the above example is isolated.
 A vertex is pendent i it has degree 1.
 Consequently, a pendent vertex is adjacent to exactly one other vertex.
 Vertex in graph in the above example is pendent.
 What do we get when we add the degrees of all the vertices of a graph
g

= (V ,E ) ?

 Each edge contributes 2 to the sum of the degrees of the vertices since an
edge is incident with exactly two vertices.

 This means that the sum of the degrees of the vertices is twice the number
of edges.

Theorem 1.1

The handshaking theorem

Let G = (V ,E ) be an undirected graph with e edges. Then,


2e =

X
v

deg(v):

Note that this applies even if multiple edges and loops are present.

 In the above example, there are 9 edges in the graph

. Thus, the sum

of the degree of all the vertices is 18.

 This theorem shows that the sum of the degrees of the vertices of an
undirected graph is even.

 So far we discussed about undirected graphs, now we shall discuss about


directed graphs.

De nition 1.8

Adjacent Vertices, Initial Vertex and Terminal Vertex.

1) When (u,v) is an edge of the graph

with directed edges,

is said to

be adjacent to v and v is said to be adjacent from u.


2) The vertex

is called the initial vertex of (u,v), and

is called the

terminal vertex of (u,v).


3) The initial vertex and terminal vertex of a loop are the same.

De nition 1.9

In-Degree and Out-degree

1) In a directed graph, the in-degree of a vertex v, ie.

deg

(v), is the number

of edges with v as their terminal vertex. (incoming edges)


2) The out-degree of v, ie. deg +(v), is the number of edges with v as their
initial

vertex. (outgoing edges)


7

3) A loop at a vertex contributes 1 to both the in-degree and the out-degree


of this vertex.

 Consider the following gure.


|-> Figure ( g. 2 p. 439)

 The in-degrees of , , , , , and in are 2, 2, 3, 2, 3, 0, respectively.


 The out-degrees of , , , , , in are 4, 1, 2, 2, 3, 0, respectively.
 We shall discuss some special types of simple graphs.
a

De nition 1.10

Complete Graphs

The complete graph on n vertices, denoted by K , is the simple graph that


n

contains exactly

one edge

between each pair of distinct vertices.

 The following gure shows examples of complete graphs.


|-> Figure ( g. 3. p. 440)

De nition 1.11
The cycle
2g,

Cn

Cycle graphs

where n  3 consists of n vertices v1, v2, ..., v and edges fv1,


n

2, v3g, ..., fv 1, v
n

g and f

vn

, v1g.

 The following gure shows examples of cycles.


|-> Figure ( g. 4 p. 440)

 We can obtain the wheel when we add an additional vertex to the


cycle , for  3, and connect this new vertex to each of the vertices,
Wn

Cn

by new edges.
8

 The following shows wheels

3,

4,

5 and W6 .

|-> Figure ( g. 5 p. 448)

 The n-cube, denoted by

Qn

, is the graph that has vertices representing

the 2 bit strings of length n.


n

 Two vertices are adjacent i the bit strings that they represent di er in
exactly one bit position.

 The following shows 1-cube, 2-cube and 3-cube.


|-> Figure ( g. 6 p. 449)

 Sometimes, a graph has the property that its vertex set can be divided
into two disjoint subsets such that each edge connects a vertex in one subset
to a vertex in the other subset.

De nition 1.12

Bipartite graphs

1) A simple graph G 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 and a vertex in V2.
2) No edge in G connects either two vertices in V1 or two vertices in V2.

Example 1.2

Bipartite

1) The cycle graph C6 is bipartite, as illustrated by the following gure.


|-> Figure ( g. 7 p. 442)
2) However, the complete graph

3 is not bipartite, since each vertex is

connected to every other vertex by an edge.


9

De nition 1.13

Complete Bipartite Graphs

1) The complete bipartite graph

Km;n

is the graph that has its vertex set

partitioned into two subsets of m and n vertices, respectively.


2) There is an edge between two vertices i one vertex is in the rst subset
and the other vertex is in the second subset.

 The following gure shows the complete bipartite graphs

2 3,

3 3,

35

and K2 6.
;

|-> Figure ( g. 9 p. 443)

1.4 Subgraphs

 When edges and vertices are removed from a graph, without removing
endpoints of any remaining edges, a smaller graph is obtained.

 Such a graph is called a subgraph of the original graph.


De nition 1.14
A

of a graph

subgraph

and F

Subgraphs
G

= (V ,E ) is a graph

= (W ,F ) where

 Consider the following graphs.


|-> Figure ( g. 14 p. 446)

 The graph is a subgraph of 5.


 Two or more graphs can be combined in various ways.
 The new graph that contains all the vertices and edges of these graphs is
G

called the union of two simple graphs.


10

De nition 1.15

Union of graphs

The union of two simple graphs


simple

graph with vertex set V1

1 = (V1,

1) and

2 and edge set E1

2 = (V2 ,

2 ) is the

2.

 Consider the following gure which shows an example of the union of two
graphs.
|-> Figure ( g. 15 p. 447)

1.5 Graphs as Matrices

 There are many useful ways to represent graphs.


 One way to represent a graph without multiple edges is to list all the
edges of this graph.

 Another way to represent a graph with no multiple edges is to use adjacency lists,

which specify the vertices that are adjacent to each vertex of

the graph.

 Consider the following example.


|-> Figure ( g. 1 p. 450)
|-> Figure (table 1 p. 450)

 However, those two kinds of representation can be cumbersome if there


are many edges in the graph.

 To simplify computation, graphs can be represented using matrices.


 There are two types of matrices : one that is based on the adjacency of
vertices, and the other that is based on incidence of vertices and edges.
11

 We shall discuss the matrix based on the adjacency of vertices.


De nition 1.16

Adjacency Matrices

Suppose that the vertices of G are listed arbitrarily as v1, v2, ..., v .
n

The adjacency matrix A of G wrt this listing of vertices, is the n  n zeroone matrix with 1 as its (i,j )th entry when v and v are adjacent, and 0 as
i

its (i,j )th entry when they are not adjacent.

 Consider the following graphs.


|-> Figure ( g. 3 p. 452)

 The following adjacency matrix represents this graph.


0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0

 Note that an adjacency matrix of a graph is based on the ordering chosen


fro the vertices.

 Hence, there are as many as

di erent adjacency matrices for a graph

with n vertices.

 The adjacency matrix of a simple graph is symmetric, that is = .


 When multiple edges are present, the adjacency matrix is no longer a
aij

aj i

zero-one matrix, since the (i,j )th entry of this matrix equals the number of
edges that are associated to f a , a
i

g.

12

 Consider the following graph.


|-> Figure ( g. 5 p. 452)

 The following is the adjacency matrix which represents this graph.


0 3 0 2
3 0 1 1
0 1 1 2
2 1 2 0

All undirected graphs, including multigraphs and pseudographs, have

symmetric adjacency matrices.

 Adjacency matrices can also be used to represent directed multigraphs.


 Now, we shall discuss another kind of matrices : incidence matrices.
De nition 1.17

Incidence Matrices

Suppose that v1, v2, ..., v are the vertices and e1, e2, ..., e are the edges
n

of G.
The incidence matrix with respect to this ordering of
m

and

matrix M = [m ] where
ij

mij

8
><1
=
>:0

when edge

ej

otherwise

 The following shows a graph.


13

is incident with

vi

is the

|-> Figure ( g. 6 p. 453)

 The following incidence matrix represents this graph.


1

1 1 1 0 0 0 0

2 0 0 1 1 0 1

3 0 0 0 0 1 1

4 1 0 1 0 0 0

5 0 1 0 1 1 0
 Incidence matrices can also be used to represent multiple edges and loops.
v

Multiple edges are represented in the incidence matrix using columns

with identical entries, since these edges are incident with the same pair of
vertices.

 Loops are represented using a column with exactly one entry equal to 1,
corresponding to the vertex that is incident with this loop.

 Consider the following graph.


|-> Figure ( g. 7 p. 454)

 The following incidence matrix represents this graph.

14

1 1 1 1 0 0 0 0 0

2 0 1 1 1 0 1 1 0

3 0 0 0 1 1 0 0 0

4 0 0 0 0 0 0 1 1

5 0 0 0 0 1 1 0 0

1.6 Isomorphism of Graphs

 We often need to know whether it is possible to draw two (possibly different) graphs in the same way.

 Formally, two graphs are isomorphic if there is a one-to-one correspondence

(bijection) between their vertex sets, that preserves

De nition 1.18

edges.

Graph Isomorphism

The simple graphs G1 = (V1, E1) and G2 = (V2, E2) are isomorphic if there
is a bijection f from V1 to V2 with the property that
for all a and b in V1,
a

and b are adjacent in G1 i f (a) and f (b) are adjacent in G2

 Such a one-to-one correspondence between vertices of two graphs preserves


the adjacency relationship between any two vertices.

Example 1.3

Graph Isomorphism

Show that the following two graphs are isomorphic.


15

|-> Figure ( g. 8 p. 454)


The function f with f (u1) = v1, f (u2) = v4, f (u3) = v3, and f (u4) = v2 is
a bijection between sets of vertices of the two graphs.

In G, the adjacent vertices are f(u1, u2), (u1, u3), (u2, u4), (u3, u4) g.

which are preserved in H by f as f (v1, v4), (v1, v3), (v4, v2), (v3, v2) g.

 It is often dicult to determine whether two simple graphs are isomorphic.


 There are ! possible one-to-one correspondences between the vertex sets
n

of two simple graphs with n vertices.

 However, we can often show that two simple graphs are not isomorphic
by showing that they do no share a property that isomorphic simple graphs
must both have.

 However, two simple graphs are not isomorphic if


- they have di erent number of vertices, or
- they have di erent number of edges, or
- the degrees of the vertices in two graphs are di erent.

Example 1.4

Graph Isomorphism

Consider the following graphs.


|-> Figure ( g. 9 p. 455)
Both two graphs have the same number of vertices and edges. But

a vertex of degree 1, namely e, whereas G has no vertices of degree 1.


Thus, the two graphs are not isomorphic.
16

has

However, when those three criteria hold for two graphs, they do not

necessarily mean that the two graphs are isomorphic.

 There are no useful sets of such criteria known that can be used to determine whether simple graphs are isomorphic.
Consider the following graphs.
Figure ( g 10 p. 461)

The two graphs

and

satisfy the three criteria, but they are not

isomorphic.

 Note that due to deg(a) = 2 in


y

, a must correspond to either t,

u, x,

or

in H , since these are vertices of degree 2 in H .

 However, each of these four vertices in

is adjacent to another vertex of

degree 2 in H , which is not true for a in G.

1.7 Connectivity

 Many problems can be modeled with paths formed by traveling along the
edges of graphs.

 For instance, the problem of determining whether a message can be sent


between two computers using intermediate links can be studied with a graph
model.

 We de ne the basic concepts in graph theory as follows.

17

De nition 1.19
1) A

path

Path

of length n from u to v, where

 1, in an undirected graph is

a sequence of edges e1, ..., e of the graph such that


n

( 1) = fx0, x1g,

f e

( 2) = fx1, x2g,

f e

.
.
.

( ) = fx 1, x

f en

where x0 = u and x = v.
n

2) When the graph is simple, we denote this path by its vertex sequence x0,
x

1, ..., x .
n

3) The path is a circuit if it begins and ends at the same vertex, that is, if
u

= v.

4) A path or circuit is simple if it does not contain the same edge more than
once.

 When it is not necessary to distinguish between multiple edges, we will


use a sequence of vertices to represent a path which is normally represented
by a sequence of edges.

Example 1.5

Paths and Circuits

Consider the following simple graph.


|-> Figure ( g. 1 p. 463)
18

 , , , ,
 , , , ,
 The path
a

is a simple path of length 4.


is a circuit of length 4.

, b, e, d, a, b is not simple.

 Similar de nitions for paths and circuits can be de ned for directed graphs.
De nition 1.20

Paths in directed graphs

A path of length

where

 1, from u to v in a directed multigraph is a

sequence of edges e1, e2, ..., e of the graph such that


n

( 1) = (x0, x1),

f e

( 2) = (x1, x2),

f e

.
.
.
( ) = (x 1, x )

f en

where x0 = u and x = v.
n

Note that each pair of vertices which forms a step in a path here is

represented by an ordered pair.

1.8 Connectedness in Undirected Graphs

 Sometimes, we are interested in nding out the conditions which ensures


that there is always a path between two vertices in a graph.

19

De nition 1.21
An

Connected

graph is called

undirected

connected

if there is a path between every

pair of distinct vertices of the graph.

Example 1.6

Connected

Consider the following graphs.


|-> Figure ( g. 2 p. 464)
- Graph G is connected.
- Graph H is not connected, since there is no path between vertices a and
d

 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.

De nition 1.22 The maximally connected subgraphs of a graph is called


connected components.

 Consider the following gure.


|-> Figure ( g. 3 p. 464)

 Obviously,

1 , G2 and

3 are the connected components of

20

De nition 1.23

Cut vertices and Cut Edges

1) If the removal of a vertex and all edges incident with it produces a graph
with more connected components than the original graph, then such a vertex
is called a cut

vertex.

2) If the removal of an edge creates a graph with more connected components, then such an edge is called a cut

edge.

 In the star network, the centre vertex is a cut vertex.

All edges are cut

edges.
|-> Figure (p. 6 Kenneth's transparency)

 In gure 4 (p. 470), the cut vertices of graph

are b,

c, e.

1.9 Connectedness in Directed Graphs

 There are two notions of connectedness in directed graphs, depending on


whether the directions of the edges are considered.

De nition 1.24

Strongly and weakly connected

1) A directed graph is strongly

connected

if there is a path from a to b and

from b to a, for every vertices a and b in the graph.

 For a directed graph to be strongly connected, there must be a sequence


of directed edges from any vertex in the graph to any other vertex.
2) A directed graph is weakly

connected

if there is a path between any two

vertices in the underlying undirected graph.

21

 A directed graph is weakly connected i there is always a path between


two vertices when the directions of the edges are disregarded.

 Clearly, any strongly connected directed graph is also weakly connected.


 Consider the following gure.
|-> Figure (p. 7 from Kenneth's transparency)

1.10 Euler Paths

 The town of Konigsberg, Prussia was divided into four sections by the
branches of the Pregel river.

 In the 18th century, seven bridges connected these regions.


|-> Figure ( g. 1 and g. 2 p. 473)

 People in the town wondered whether it was possible to start at some


location in the town, travel across all the bridges without crossing any
bridge twice, and return to the starting point.

 The Swiss mathematician Leonhard Euler solved this problem.


 His solution published in 1736 may be the rst use of graph theory.
 The problem was reduced to the following question:
Is there a simple circuit in this multigraph that contains every edge ?

De nition 1.25

Euler Circuit

An

in a graph

Euler circuit

is a simple circuit containing every edge of

.
22

 Determine whether the following graphs have an Euler circuit.


|-> Figure ( g. 3 p. 474)

1 has an Euler circuit, ie. a, e, c, d, e, b, a. However, the other do not

have an Euler circuit.

 Euler solved the problem by showing that there is no such Euler circuit
in the graph representing the bridges.

2 Trees
 A connected graph that contains no simple circuits is called a tree.
 It can be traced back to 1857 when the English mathematician Arthur
Cayley used tree to analyse chemical compounds.

De nition 2.1

Tree

A tree is a connected undirected graph with no simple circuits.

 Since a tree cannot have a simple circuit, a tree cannot contain multiple
edges or loops.

 Thus, any tree must be a simple graph.


 Consider the following graphs and decide which one is a tree.
|-> Figure ( g. 2 p. 532)

1 and

2 are trees, since they both are connected and do not have a

simple circuit.

23


d

4 is not a tree since it is not connected.

3 is not a tree because e, b, a,

, e is a simple circuit.

 The following is an important property of a tree.


Theorem 2.1 An undirected graph is a tree i there is a
path between any

De nition 2.2

two

unique simple

of its vertices.

Forest

A forest is a graph that are not necessarily connected but contains no simple
circuits, and each of its connected components is a tree.

 Consider the following gure showing an example of forest.


|-> Figure ( g. 3 p. 533)

 In many applications of trees, a particular vertex of a tree is designated


as the root.

 It follows from the above theorm that there is a unique path from the
root to each vertex of the graph.

 Thus, we can direct each edge from the root.


 We can change an unrooted tree into a rooted tree by choosing any vertex
as the root.

 Consider the following example.


|-> Figure ( g. 4 p. 534)

24

De nition 2.3
1) If

Some terminalogies

is a vertex in a tree which is not the root, the

parent

of

is the

unique vertex u such that there is a directed edge from u to v.


2) Thus, v is said to be a child of u.
3) Vertices with the same parent are called siblings.
4) The ancestors of a vertex which is not a root are the vertices in the path
from the root to this vertex, excluding the vertex itself and including the
root.
5) The decendants of a vertex v are those vertices that have v as an ancestor.
6) A vertex of a tree is called a leaf if it has no children.
7) Vertices that have children are called internal

vertices.

8) If a is a vertex in a tree, the subtree with a as its root is the subgraph of


the tree consisting of a and its descendants and all edges incident to these
descendants.
|-> Figure ( g. 5 p. 535)

De nition 2.4

M-ary Trees

1) A rooted tree is called an m-ary tree if every internal vertex has no more
than m children.
2) The tree is called a full m-ary tree if every internal vertex has exactly m
children.
3) An m-ary

tree

with m = 2 is called a binary

|-> Figure ( g. 7 and g. 8 p. 536 - 537)


25

tree.

You might also like