Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 4 (Discrete Math)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 72

DISCRETE M A T H E M A T I C S A N D COMBINATORICS

CHAPTER FOUR

Graph Theory

September 28, 2022 1


Graph Definitions
Definition 1.1
A graph G consists of a finite non–empty set of vertices V and a finite
(possibly empty) set E of unordered pairs of elements of V (called the
edges).

We write the graph G as G = (V, E), where V = {v1, v2, . . . vn} is a


set of vertices and E = {{vi , vj }|vi , vj ∈ V } is a set of edges.
Vertices are usually represented by means of dots on the plane
and the edges by means of lines connecting these dots.
We denote vertices by letters: u, v,... or v 1, v 2, . . . or simply by
numbers 1, 2, . . ..
We denote edges by e1, e2,... or by their two endpoints.
An edge e = {u, v} is usually written as uv (or vu). That means
the edges are undirected.
3
Graph Definitions

Example 1.1
Consider the graph G = (V , E ), where

V = {a, b, c, d} and E = { {a, c},{a, b},{b, c},{b, d},{c, d} }.

Hence, the graph G becomes

a b

c d

Figure 1: The graph G = (V , E ).

4
Order and Size
Definition 1.2
The number of vertices in a graph G = (V, E) is called its order, and the
number of edges is its size. That is, the order of G is card (V) and its size
is card (E).

Example 1.2
Consider the graphs:
a a d
a
a c
G1 G2
b b
G3
c
G4
b

We see that, the order of G1 is card (V) = 1 and its size is card (E) =
0. The order of G2 is 2 and its size is 1.
The order of G3 is 3 and its size is 3. The order of G4 is 4 and its
size is 5.
5
Adjacent Vertices
Definition 1.3
Two vertices u and v are said to be adjacent (neighbours) if there exists
an edge e = {u, v} (or simply e = uv) in the graph G = (V, E).
We call u and v the end-vertices of the edge e.

If u and v are end-vertices of the edge e, then we say that


1 the vertices u and v are incident with the edge e, or
2 the edge e is incident with the vertices u and v .

Example 1.3
The vertices v1 and v2 are adjacent. Similarly, v1 and v4 are adjacent.
v2 v5

v1
v3 v4

6
Adjacent Vertices
Definition 1.4
Two edges are adjacent if they have a vertex in common.

Example 1.4
The edges e1 and e2 are adjacent edges. Similarly, e2 and e3 are adjacent
edges.

v2 v5
e1
e4 v1 e6
e2
e3
v3 v4
e5

But, e3 and e4 are not adjacent edges.

7
Parallel edges and Loops
If there is more than one edge between the same pair of vertices,
then the edges are termed as parallel edges.
Example 1.5
In the graph G , the edges e4 and e5 are parallel edges.

e1
e4 e6

A e5 B e7 C

Similarly, e6 and e7 are parallel edges.


8
Parallel edges and Loops
An edge whose starting and ending vertex are same is known as
a loop. Such edge is written as e = {v, v}, where v is a vertex on
the graph.
Loops are edges incident to only one vertex.

Example 1.6
In the graph given below, the edges e4 and e5 are loops.
e1

e2
e4 v1 v2 e5
e3

Note that the edges e1, e2 and e3 are parallel edges.


9
Common Types of Graph

10
Simple Graph

Definition 2.1
A graph G = (V, E) that has no loop and no parallel edges is called a
simple graph.

Example 2.1
The following graph is a simple graph as it has no loop and no parallel
edges.
v2 v4

v1 v3 v5

11
Multi Graph
Definition 2.2
A graph G = (V, E) is known as a multi graph if it contains parallel edges,
(i.e. two or more edges between a pair of vertices).

Example 2.2
The graph given G given below is a multi graph as it contains parallel
edges.
D

A B C

Note that every simple graph is a multi graph, but the converse

12
Pseudo Graph
Definition 2.3
A graph G = (V, E) is known as a pseudo graph if it contains loops, and
possibly parallel edges connecting the same pair of vertices or a vertex
to itself.

Example 2.3
The graph given below is a pseudo graph.

A B

Note that every multi graph is pseudo graph but the converse

13
Directed Graph (Digraph)

14
Definition 3.1
A directed graph (or digraph) G = (V , E ) consists of a nonempty set of
vertices V and a set of directed edges E in which each edge is associated
with an ordered pair of vertices.
The directed edge associated with the ordered pair (u, v) starts at u and
ends at v.

Example 3.1
The following graph is a digraph.

v2 v5

v1

v3 v4

15
Degree of a vertex

16
Degree of a vertex
Definition 4.1
In an undirected graph, the degree of a vertex v , denoted by deg(v), is
the number of edges incident to it.

Example 4.1
Find the degree of each vertices in the following graph.

c b f

a e d

Solution: We have

deg(a) = 2, deg(b) = 3, deg(c) = 2, deg(d) = 2, deg(e) = 3, deg(f) = 2.

17
Degree of a vertex
Note: In case of a loop, it contributes 2 to the degree of a vertex.
Example 4.2
Find the degree of vertices in the given graph.

a b

Solution:
Observe that a loop at vertex a and vertex b contributes twice
to the degree of the two vertices.
So we have,
deg(a) = 2 + 3 = 5, deg(b) = 2 + 3 = 5, and deg(c) = 2.

18
Degree of a vertex
In case of a digraph there are two degrees known as in–degree
and out–degree.
The in–degree of a vertex v in a digraph, denoted by deg+(v), is
the number of edges with v as the terminal vertex.
The out–degree of v , denoted by deg−(v), is the number of edges
with v as the initial vertex.
Example 4.3
Find the in–degree and out–degree of vertices in the graph given below.
c

a b

Solution:
The in–degrees are: deg+(a) = 3, deg+(b) = 2, deg+(c) = 1.
The out–degrees are: deg−(a) = 2, deg−(b) = 3, deg−(c) = 1.

19
Degree of a vertex
Definition 4.2
A vertex is said to be an isolated vertex if it is not adjacent to any vertex.
It follows that an isolated vertex is a vertex of degree zero.
That is, if deg(v) = 0, then v is isolated.

Example 4.4
In the graph G given below, the vertex f is an isolated vertex.
a
e b f
d c

Definition 4.3
A vertex is said to be pendant vertex if it is adjacent to exactly one other
vertex. Consequently, a pendant vertex has degree one.
Vertex e in the above graph is pendant.
20
Degree of a vertex
The Handshaking Theorem

Theorem 4.1 (Handshaking Theorem)


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

∑ deg(vi) = 2m.
vi∈V

Example 4.5
The graph G contains 5 vertices with degrees 4, 3, 2, 2, 1. How many edges
are there in G ?

Solution: Let m be the number of edges in a graph.


Then, we get 2m = 4 + 3 + 2 + 2 + 1 = 12 =⇒ m = 6.
Therefore, G has 6 edges.

21
Special Simple Graphs

22
Complete Graphs
Definition 5.1
A complete graph is a simple graph in which each pair of vertices is
adjacent. The complete graph with n vertices is denoted Kn.

Note that Kn has n(n−1)


number of edges.
2
Example 5.1
For n = 1, 2, 3, 4, 5, the graphs Kn are given as follows:
v0 v1 v1
v2

v2 v0 v0

v0 v1 v0 v1 v2 v3
K1 K2 K3 v3 K4 K5 v4

A simple graph with at least two non–adjacent vertices is called


non–complete graph.
September 28, 2022 23
Cycles
Definition 5.2
A cycle of length n is a simple graph that contains n vertices v1, v2, . . . , vn
and n edges {v1, v2},{v2, v3}, . . . ,{vn−1, vn}, and {vn, v1}. For n ≥ 3, a cycle
of length n is denoted by Cn.

Example 5.2
The cycles C3, C4, C5, and C6 are given as follows:

v1
v1 v1
v2 v2 v1
v0 v0
v2 v0 v3 v0
v2 v3
v3 v4 v4 v5
C3 C4 C5 C6

24
Wheels

Note
We obtain a wheel Wn when we add an additional vertex to a cycle
Cn, for n ≥ 3, and connect this new vertex to each of the n vertices
in Cn by new edges.

Example 5.3
The wheels W3, W4, W5, and W6 are:

v1 v1 v2 v1
v1 v2
v3 v0 v2 v4 v0 v5 v0 v3 v6 v0
v2 v3
v3 v4 v4 v5

W3 W4 W5 W6

25
Bipartite Graphs
Definition 5.3
Bipartite graph is a graph G = (V , E ) whose vertex set V can be par-
titioned into two non–empty disjoint sets V1 and V2 such that each edge
of the graph G has one end–vertex in V1 and the other end–vertex in V2.
That is, no two vertices within the same set are adjacent.

Example 5.4
The cycle C6 is bipartite. Because its vertex set can be partitioned into
the two sets: V1 = {v0, v2, v4} and V2 = {v1, v3, v5}.

v0 v1

v2 v3

v4 v5

26
Complete Bipartite Graph
Definition 5.4
A complete bipartite graph is a bipartite graph in which every vertex of
the first set is connected to every vertex of the second set.
If there are m and n vertices in the two sets, the complete bipartite graph
is denoted by Km,n.

Example 5.5
The following three graphs are complete bipartite graph.
v
b0 b1 b0 b1 b2 b0 b1 b2

v0 v1 v2 v0 v1 v2 v0 v1 v2 v3
K3,2 K3,3 K4,3

27
Regular Graph
Definition 5.6
A simple graph is called a regular graph if every vertex of this graph has
the same degree.
A regular graph is called n–regular if every vertex in this graph has de-
gree n.

Example 5.7
The following graphs are all regular.

Note that: for each n, Cn, Qn and Kn,n are some special n–regular graphs.
28
Graphic Sequences

29
Degree Sequence
Definition 6.1
The degree sequence of a graph is the sequence of the degrees of the
vertices of the graph in decreasing order.

Example 6.1
Find the degree sequence of the following graphs.

Solution: The degree sequence is (3, 2, 2, 2, 2, 1), (4, 4, 4, 2, 2, 2), (4, 3, 3, 3, 3)


and (4, 4, 3, 3, 3, 3) respectively.

30
Degree Sequence
Example 6.2
How many edges does a graph have if its degree sequence is 4, 3, 3, 2, 2?
Solution: The graph has 7 edges, since 4+3+3+2+2
= 14
= 7.
2 2

Definition 6.2
A sequence d1, d2, . . . , dn is called graphic sequence if it is the degree
sequence of a simple graph.

Example 6.3
The sequence 2, 2, 2 is graphic, since K3 is a graph with this degree se-
quence.
In general, the sequence n, n,..., n is graphic since Kn+1 has this

degree sequence.
31
Theorem 6.1 (Havel–Hakimi)

Subgraph

32
Subgraph and Induced Subgraph
Definition 7.1
Let G1 = (V1, E1) and G2 = (V2, E2) be two simple graphs. We say that
1 G1 is a subgraph of G2 provided that V1 ⊆ V2 and E1 ⊆ E2.
2 G1 is an induced subgraph of G2 (the subgraph induced by V1) pro-
vided that each pair of vertices in V1 are adjacent in G1 if and only
if they are adjacent in G2.

Note that every induced subgraph is a subgraph, but the con-


verse may not be true.
A subgraph is the result of deleting some vertices and edges
from the larger graph.
But, in case of induced subgraph we can only delete edges that
are incident with the deleted vertices.

33
Subgraph and Induced Subgraph

Example 7.1
Consider the following graphs.

f f f

d e d d d

a b c a b c a b c a b c
G1 G2 G3 G4

Note that both G2 and G3 are subgraphs of G1.


But only G2 is an induced subgraph. In G3, the edge {a, b} is in
E1 but not in E3, even though vertices a and b are in V3.
The graph G4 is not a subgraph of G1 since the edge {c, f } is in
E4, but {c, f } is not an element of E1.

34
Matrix Representation of Graphs

35
Adjacency Matrix
A matrix is a convenient way of representing a graph.
Two types of matrices are commonly used to represent graphs:
adjacency matrix and incidence matrix.
The adjacency matrix is based on the adjacency of vertices, and
the incidence matrix is based on incidence of vertices and edges.
Adjacency Matrix
Let G = (V , E ) be a simple undirected graph with n number of ver-
tices that are listed arbitrarily as v1, v2, . . . , vn. The adjacency matrix
for G with respect to this listing of vertices is a square matrix (zero–
one matrix of order n ×n) A = [aij] where

36
Adjacency Matrix

37
Adjacency Matrix
Adjacency matrices can also be used to represent multi graphs
and pseudo graphs.
A loop at the vertex vi is represented by aii = 1.
When multiple edges connecting a pair of vertices vi and vj
are present, the entry aij equals the number of edges that are
associated to the edge {vi, vj}.
Adjacency Matrix
Adjacency matrices can also be used to represent
digraphs. Again, when there are multiple edges from vertex vi
to vertex vj , the entry aij equals the number of edges that are
associated to the directed edge (vi, vj).

Note that the adjacency matrix for any undirected graph is symmetric. But,
for a digraph it may not be symmetric.
. 42
Incidence Matrix

44
Incidence Matrix
Incidence matrices can also be used to represent multiple edges
and loops.
Multiple edges are represented in the incidence matrix using
columns with identical entries, because these edges are incident
with the same pair of vertices.
Loops are represented using a column with exactly one entry
equal to 1.

45
Module #22 - Graphs
Incident matrix of diagraph

1
Module #22 - Graphs

Exercise
1. Find adjacency matrix

A(G) =

11/14/2023 2
Module #22 - Graphs

Graph Isomorphism
• Formal definition:
– Simple graphs G1=(V1, E1) and G2=(V2, E2)
are isomorphic iff  a bijection f:V1→V2
such that  a,bV1, a and b are adjacent in
G1 iff f(a) and f(b) are adjacent in G2.
– f is the “renaming” function between the two
node sets that makes the two graphs
identical.

11/14/2023 3
Module #22 - Graphs

Graph Invariants under Isomorphism

Necessary but not sufficient conditions for


G1=(V1, E1) to be isomorphic to G2=(V2, E2):
– We must have that |V1|=|V2|, and |E1|=|E2|.
– The number of vertices with degree n is the
same in both graphs.
– For every proper subgraph g of one graph, there
is a proper subgraph of the other graph that is
isomorphic to g.

11/14/2023 4
Module #22 - Graphs
Example 1

1 a
2 b
3 d
4 c

5
Module #22 - Graphs

Example 2
• Is the two graph Isomorphism? If isomorphic,
label the 2nd graph to show the isomorphism,
else identify difference.
b d
a b a
d c
e
e c f
f

11/14/2023 6
Module #22 - Graphs

Connectivity
❖ Basic Idea: In a Graph Reachability among vertices by
traversing the edges
Application Example:

➢ In a city to city road-network, if one city can be reached


from another city.

➢ Problems if determining whether a message can be sent


between two computer using intermediate links

➢ Efficiently planning routes for data delivery in the Internet


11/14/2023 7
Module #22 - Graphs

Walks, Trails, Path, Circuit and Cycle in


undirected graphs
• Walk: a sequence of edges and vertices of a graph.
• When we have a graph and traverse it, then that traverse will be
known as a walk.
• In a walk,
✓ Edges can be repeated
✓ Vertex can be repeated
▪ The number of edges which is covered in a walk will be known
as the Length of the walk. In a graph, there can be more than one
walk.

11/14/2023 8
Module #22 - Graphs

Example

• In the above graph, there can be many walks, but some of


them are described as follows:
1. A, B, C, E, D (Number of length = 4)
2. D, B, A, C, E, D, B, C (Number of length = 7)
3. E, C, B, A, C, E, D (Number of length = 6)
11/14/2023 9
Module #22 - Graphs

Types of Walks
• There are two types of the walk, which are described as follows:
❖ Open Walk: If the vertices at which the walk starts and ends are
different. That means for an open walk, the starting vertex and
ending vertex must be different.

❖ Closed Walk: If the vertices at which the walk starts and ends are
identical. That means for a closed walk, the starting vertex and
ending vertex must be the same.
• In a closed walk and open walk, the length of the walk must be
more than 0.
11/14/2023 10
Module #22 - Graphs

Example

• In this graph,
• Closed walk = A, B, C, D, E, C, A
• Open walk = A, B, C, D, E, C

11/14/2023 11
Module #22 - Graphs

Definition Cont. ...


• Trails: is a walk where no edge is allowed to
repeat but the vertex can be repeated.

• Path: is a type of walk where neither edges nor


vertices are allowed to repeat.

• There is a possibility that only the starting


vertex and ending vertex are the same in a path.

11/14/2023 12
Module #22 - Graphs

Definition Cont. ...


• Circuit: is a closed walk where no edge is allowed to
repeat but vertex can be repeated. A closed trail in the
graph theory is also known as a circuit.

• Cycle: is a type of closed walk where neither edges nor


vertices are allowed to repeat. A closed path in the graph
theory is also known as a Cycle.
• There is a possibility that only the starting vertex and
ending vertex are the same in a cycle.
11/14/2023 13
Module #22 - Graphs

Example

Tail = A, C, H, F, C, B
Path: F, H, C, A, B, D
Closed tail = A, C, H, F, C, B, A
11/14/2023 14
Module #22 - Graphs

Example

Cycle: A, B, D, C, A Circuit: A, B, D, C, F, H, C, A
11/14/2023 15
Module #22 - Graphs

Exercise
Find out which sequence of the vertices determines walks.
1. A, B, G, F, C, D
2. B, G, F, C, B, G, A
3. C, E, F, C
4. C, E, F, C, E
5. A, B, F, A
6. F, D, E, C, B

11/14/2023 16
Module #22 - Graphs

Solution
1. Sequence no 1 is a Trail because there is no repeated edge in the
sequence ABGFCB.
2. Sequence no 2 is a Walk because the sequence BGFCBGA
contains the repeated edges and vertices.
3. Sequence 3 is a Cycle because the sequence CEFC does not
contain any repeated vertex or edge except the starting vertex C.
4. Sequence no 4 is a Walk because the sequence CEFCE contains
the repeated edges and vertices.
5. Sequence no 5 is Not a Walk because there is no direct path to go
from B to F. That's why we can say that the sequence ABFA is
not a Walk.
6. Sequence no 6 is a Path because the sequence FDECB does not
contain any repeated edges and vertices.
11/14/2023 17
Module #22 - Graphs

Exercise
Find out which sequence of the vertices determines walks

1. v1, e1, v2, e2, v3, e2, v2


2. v4, e7, v1, e1, v2, e2, v3, e3, v4, e4, v5
3. v1, e1, v2, e2, v3, e3, v4, e4, v5
4. v1, e1, v2, e2, v3, e3, v4, e7, v1
5. v6, e5, v5, e4, v4, e3, v3, e2, v2, e1, v1, e7, v4, e6, v6

11/14/2023 18
Module #22 - Graphs

Remarks

❖ Every path can be a trail, but it is not possible that


every trail is a path.

❖ Every cycle can be a circuit, but it is not important that


every circuit is a cycle.

11/14/2023 19
Module #22 - Graphs

Important Chart:
• The above definitions can be easily remembered with the help of
following chart:

11/14/2023 20
Module #22 - Graphs

Euler Paths and Circuits

1. Euler Path: is when a trail/walk on a graph


visits each edge exactly once.
• If you can start at a vertex and move to every
single edge, it is an Euler path.
• A connected multigraph has an Euler path iff it
has exactly 2 vertices of odd degree.
– One is the start, the other is the end.
11/14/2023 21
Module #22 - Graphs

Cont. …
2. Euler circuit: is much like the Eulerian path,
but you start at one vertex, visit every vertex
exactly once, then end on your starting vertex.
• If a graph has an Euler circuit it cannot have an
Euler path and vice versa.
• If every vertex is an even degree it is an Eulerian
graph or
• A connected graph G is Eulerian if and only if G
is connected and has no vertices of odd degree.
11/14/2023 22
Module #22 - Graphs

Bridges of Königsberg Problem


• Can we walk through town, crossing each bridge
exactly once, and return to start?
A

B D

C
The original problem Equivalent multigraph

Soln: No b/c it has no tour/ path that uses each edge exactly once.
(Even if we allow the walk to start and finish in different places.)
11/14/2023 23
Module #22 - Graphs

Example
• Does the graph has Euler circuits or Euler
paths?

• It has no Euler circuits but it has Euler paths


(for example C, D, E, B, A, D)
11/14/2023 24
Module #22 - Graphs

Hamiltonian Paths and Circuits


1. Hamiltonian Path: is a path that visits each vertex
exactly once.
2. Hamilton Circuit: is a circuit that visits every vertex
once (except for the starting and ending vertex)
• If graph has Hamilton circuit is also known as
Hamiltonian graph.
• If a graph has a Hamilton circuit, then it automatically
has a Hamilton path
• The Hamilton circuit can always be truncated into a
Hamilton path by dropping the last vertex of the circuit.

11/14/2023 25
Module #22 - Graphs

Example
• Does the graph has Hamiltonian
circuits or Hamiltonian paths?

Soln. Yes, It has Hamilton


Circuits and paths. For example
A, F, B, C, G, D, E, A (Circuit)
A, F, B, C, G, D, E (Path)

11/14/2023 26
Module #22 - Graphs Summary
Module #22 - Graphs

Graph Coloring
❖ Definition: A graph has been proper colored if a color
has been assigned to each vertex in such a way that
adjacent vertices have different colors.
• A graph that can be assigned a (proper) k-coloring is k-
colorable. For Example

• 4-coloring 5-coloring
28
Module #22 - Graphs

Chromatic Number
❖ Definition: The chromatic number of a graph G is the
smallest/least number k such that G is k-colorable, and it
is denoted by χ(G).
❖ Example:
b e

a d g

c f

𝜒 𝐺 =2 𝜒(𝐺) = 3

29
Module #22 - Graphs

Exercise
❖ Find The chromatic number of the following graph
G1 G2 G3

G4 G5

30
Module #22 - Graphs

Remarks
• 𝜒 𝐺 = 1 iff G has no edges, that is, G is a null
graph.

• 𝜒 𝐺 = 2 iff G is bipartite and non-null.

• 𝜒 𝐾𝑛 = 𝑛 Where 𝐾𝑛 is a complete graph with n


vertices.

• 𝜒 𝐶𝑒𝑣𝑒𝑛 = 2 and 𝜒 𝐶𝑜𝑑𝑑 = 3 where C is a cycle


graph with even or odd number of vertices.
31
Module #22 - Graphs

Remarks Cont. …
• We usually show a k-coloring by writing the
numbers 1,2, ..., k next to the appropriate vertices.
• For example: diagrams (a) and (b) below illustrate a 4-
colouring and a 3-colouring of a graph G with five
vertices;

32

You might also like