You are on page 1of 22

Graph

CSCI1303
Mathematics for Computing I
CSCI1303 - Mathematics for Computing I Graph

Definition: Graph
A graph
𝐺 = 𝑉, 𝐸, 𝛾

consists of
a finite set 𝑉 of objects called vertices,
a finite set 𝐸 of objects called edges, and
a function 𝛾 that assigns to each edge a subset 𝑣, 𝑤 ,
where 𝑣 and 𝑤 are vertices (and may be the same).

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Graph
Let
Then the graph 𝑮 = 𝑽, 𝑬, 𝜸 can be
𝑉 = 1,2,3,4 represented as the following structures
𝐸 = 𝑒1 , 𝑒2 , 𝑒3 , 𝑒4 , 𝑒5
𝛾 𝑒1 = 𝛾 𝑒5 = 1,2 1 2 1 2

𝛾 𝑒2 = 4,3
3 4 4 3
𝛾 𝑒3 = 1,3
𝛾(𝑒4 ) = 2,4 𝑮 = { 𝟏, 𝟐 , 𝟒, 𝟑 , 𝟏, 𝟑 , 𝟐, 𝟒 }
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Definition: degree
Degree
number of edges having the specified vertex
as an end point
A B deg(A) = 3
deg(B) = 3
E C deg(C) = 1
deg(D) = 3
D deg(E) = 2
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Definition: loop

Loop
an edge from a vertex to itself
A B

E C

D
loop
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Definition: Path
A path 𝑝 in a graph 𝐺 consists of a pair 𝑉𝑝 , 𝐸𝑝 :
• 𝑉𝑝 ∶ 𝑣1 , 𝑣2 , … , 𝑣𝑘 is a vertex sequence
• 𝐸𝑝 ∶ 𝑒1 , 𝑒2 , … , 𝑒𝑘−1 is an edge sequence

where
1. Each successive pair 𝑣𝑖 , 𝑣𝑖+1 of vertices is adjacent in
𝐺,
2. and edge 𝑒𝑖 has 𝑣𝑖 and 𝑣𝑖+1 as end points for 𝑖 =
1, 2, … , 𝑘 − 1;
3. No edge occurs more than once in the edge sequence.
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Definition: Types of Path


Circuit (cycle)
a path that begins and ends at the same vertex

Simple
a path which has no vertex appears more than
once in the vertex sequence, except possibly if
𝑣1 = 𝑣𝑘
In this case, the path is called a simple circuit
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Definition: Connected, Disconnected & Component

Connected graph Example of Connected graph


A graph that contains a A B
path from any vertex to
any other vertex in the
graph E C

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Definition: Connected, Disconnected & Component

Disconnected graph Example of Disconnected graph

• Graph that is not A B

connected
Component
• Subgraphs in a C

disconnected graph
are considered as D

components of the Component


graph E F

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Types of Graph
Discrete graph
A discrete graph on 𝑛 vertices, denoted by 𝑼𝒏 , is a
graph with 𝒏 vertices {𝑣1 , 𝑣2 , …, 𝑣𝑛 } and no edges

Example of Discrete Graph

𝑼𝟐 𝑼𝟓

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Types of Graph
Linear graph
A linear graph on 𝑛 vertices, denoted by 𝑳𝒏 , is a
graph with 𝒏 vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 and edges
𝑣𝑖 , 𝑣𝑖+1 for 𝑖 = 1,2, … , 𝑛

Example of Discrete Graph

𝑼𝟐 𝑼𝟓

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Types of Graph
Complete graph
A complete graph on 𝑛 vertices, denoted by
𝐾𝑛 , is a graph with 𝑛 vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛
and with an edge for every 𝑖 and 𝑗
Example of Complete Graph

𝐾3 𝐾4 𝐾5
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Euler Path & Circuit

Euler path
is a path (in a graph, 𝐺) that contains every
edge (of graph 𝐺) exactly once

Euler circuit
is a circuit (in a graph, 𝐺) containing every
edge (of graph 𝐺) exactly once
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Euler Path & Circuit

1
A 2
Has Euler path:
E = {A, B, D, C} one of possible
paths
B C
Has Euler circuit:
3
D
4 E = {A, B, D, C} one of possible Euler
paths
G = {{1, 2}, {1, 4}, {2, 3}, {3, 4}}
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Euler Path & Circuit

1
A 2
No Euler path:
No path containing each edge exactly
E F once
B C
No Euler circuit:
3
D
4 No Euler path

G = {{1, 2}, {1, 3}, {1, 4}, {2, 3},{2, 4},{3,4}}


hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Euler Path & Circuit


G
A
Has Euler path:
E = {D, C, A, G, E, B, F} one of
E F possible paths
B C
No Euler circuit:
D The Euler path is not a circuit

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Theorems for Euler Path and Circuit


• If 𝐺 is a connected graph and every vertex has
even degree, then there is an Euler circuit in 𝐺
• If a graph 𝐺 has more than two vertices of odd
degree, then there can be no Euler path in 𝐺
• If 𝐺 is connected and has exactly two vertices of
odd degree, there is an Euler path in 𝐺. Any Euler
path in 𝐺 must begin at one vertex of odd degree
and end at the other
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Euler Path & Circuit

There has exactly two vertices of


odd degree. There is no Euler
Each of the four vertices has degree 3. circuit, but there must be an Euler
path.
There is no Euler path and Euler circuit.

Every vertex has even degree, thus the graph


must have an Euler circuit.

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Hamilton Path & Circuit


Hamilton path
is a path (in a graph, 𝐺) that contains every
vertex (of graph 𝐺) exactly once

Hamilton circuit
is a circuit (in a graph, 𝐺) that contains every
vertex (of graph 𝐺) exactly once except for the
first vertex
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Hamilton Path & Circuit


E

Has Hamiltonian path:


V = {E, D, A, B, C} one of possible paths
D

A C No Hamiltonian circuit:
Hamiltonian path is not a circuit
B

G = {{E, D}, {D, A}, {A, B}, {B, C}, {C, D}}

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Hamilton Path & Circuit

A B Has Hamiltonian path:


V = {A, B, D, C} one of possible paths

Has Hamiltonian circuit:


C D
V = {A, B, D, C, A} one of possible
Hamiltonian paths
G = {{A, B}, {A, C}, {A, D}, {B, D}, {C, D}}

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Graph

Example: Hamilton Path & Circuit

a b
No Hamiltonian path:
Disconnected graph
c
d No Hamiltonian circuit:
Disconnected graph

f e

hyaacob@iium.edu.my

You might also like