You are on page 1of 30

Some Algorithms Used In Graph Theory

Dahiru Abdurrahman

King Fahd University of Petroleum and Minerals


g202110130@kfupm.edu.sa

November 29, 2021

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 1 / 30


ABSTRACT

In this project various algorithms used in graph theory are demonstrated


together with some reasonable examples on how to apply each algorithm
to solve a particular problem.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 2 / 30


INTRODUCTION

Many real world situations can be modeled as graph theoretical problems.


This project will present algorithmic methods for solving various kind of
these problems such as finding the Eulerian path, Eulerian circuit, number
of spannning trees as well as finding the least weight spanning trees for
weighted graphs. The algorithms that are presented in this project include
Fleury’s Algorithm, Kruskal’s Algorithm, Prim’s Algorithm, Matrix tree
Algorithm, Greedy Algorithm and Edge picking Algorithm.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 3 / 30


DEFINITION OF BASIC TERMS

Euler path: An Euler path in a graph G is a path that uses every


edge of G exactly once with no repitition, but does not have to start
and end at the same edge.
Euler circuit: An Euler circuit in a graph G is a circuit that uses
every edge of G exactly once. Being a circuit, it must start and end at
the same edge.
Hamiltonian path: A Hamiltonian path in a graph G is a path that
visits every vertex of G exactly once, but does not have to start and
end at the same vertex.
Hamiltonian circuit: A Hamiltonian circuit in a graph G is a circuit
that visits every vertex of G exactly once with no repitition, it must
start and end at the same vertex.
Eulerian graph:This is a graph containing atleast one Eulerian
circuit.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 4 / 30


Hamiltonian graph:This is a graph containing atleast one
Hamiltonian circuit.
Tree: This is a connected graph with no circuit.
Weighted graph: This is a graph involving numbers assigned to each
edge.
Minimum spanning tree: The minimum spanning tree for a
weighted graph is a spanning tree with the smallest possible total
weight.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 5 / 30


THEOREMS

Theorem
1 If a connected graph G has exactly two vertices of odd degree, then G
has atleast one Euler path, but no circuit. Each Euler path must start
at one of the odd vertices and end at the other one.
2 If a connected graph G has no vertices of odd degree (all the vertices
of G has even degree) then G has atleast one Euler circuit (which by
definition is also an Euler path). The Euler circuit can start and end
at any vertex.
3 If a connected graph G has more than two vertices of odd degree,
then G has neither Euler path nor Euler circuit.

NOTE: The above theorem (Euler’s theorem) only indicate the existence
of an Euler’s path or Euler’s circuit in a graph but it does not tell us how
to find the Euler’s path or Euler’s circuit.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 6 / 30


NECESSARY AND SUFFICIENT CONDITIONS FOR THE
EXISTENCE OF HAMILTONIAN CIRCUIT
The more the nummber of edges of a graph has, the more likely for it
to have a Hamiltonian circuit.
DIRAC’S THEOREM: If G is a simple connected graph with atleast
3 vertices (i.e., n ≥ 3) such that the degree of every vertex in G is
atleast n2 (i.e., d(v ) ≥ n2 ∀v ∈ G ) then G has atleast one Hamiltonian
circuit.
ORE’S THEOREM: If G is a simple connnected graph with atleast
3 vertices (i.e., n ≥ 3) such that d(u) + deg (v ) ≥ n for every pair of
non-adjacent vertices u and v then G has atleast one Hamiltonian
circuit.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 7 / 30


FLUERY’S ALGORITHM
If Euler’s theorem indicates the existence of an Euler path or circuit in a
graph G , then one can be found by using the following procedure:
1 If the graph G has exactly two vertices of odd degree (and therefore

an Euler path), choose one of the vertices with odd degree as the
starting point (since the Euler path must start at one of these vertices
of odd degree and end at the other one). If G has no vertices of odd
degree (and therefore an Euler circuit), choose any vertex as the
starting point.
2 Assign numbers to the edges of the graph as you trace through the

graph according to the following rules:


After you have traveled over an edge erase it. (This is because you
must travel over an edge exactly once). Show the erased edges with
dashed lines.
When coming across with a choice of edges to trace, choose an edge
that is not a bridge.
Travel over an edge that is a bridge only if there is no alternative.
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 8 / 30
Example 1:
Determine whether the following graph has an Euler path or Euler circuit
and if it has, use Fleury’s algorithm to find one.

Clearly the vertices a, d and e has even degree while the vertices b and c
has odd degree. So, G has exactly 2 vertices of odd degree and thus by
Euler’s theorem, G has an Euler path which must start at one of these odd
vertices and end at the other one. By using Fleury’s algorithm, we will
found that b → a → d → a → e → d → c → e → b → c
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 9 / 30
Example 2:

Detemine whether the following graph has an Euler path or Euler circuit
and if it has, use Fluery’s Algorithm to find one.

Clearly from the graph above all the vertices of G has an even degree and
so by Euler’s theorem G has an Euler circuit.
By using Fleury’s algorithm, we will found that
E →B→C →A→D→C →F →D→H→G →F →E
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 10 / 30
MATRIX TREE ALGORITHM

This algoritnm is only used to determine the number of spanning trees in a


graph G which is not complete. But for complete graph, one can
determine the number of spanning trees using Cayley formula:
t(Kn ) = nn−2 while for complete bipartite graph t(Km,n ) = mn−1 nm−1 .
If a graph G is not complete, one can determine the number of spanning
trees of G , using the Matrix tree Algorithm below:
1 Create an adjacency matrix for the given graph
2 Replace all the diagonal elements with the degrees of vertices of G
3 Replace all the non-diagonal elements equals 1 with -1
4 Calculate the cofactor of any element and the result will give you the
total number of spanning trees in G .

Example

Find the number of spanning trees of the following graph below:


Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 11 / 30
Step 1: The adjacency matrix of G is given below
 
0 1 1 1
1 0 0 1
A= 1

0 0 1
1 1 1 0

Step 2: Replace all the diagonal entries of A with the degrees of the
vertices
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 12 / 30
 
3 1 1 1
1 2 0 1
A=
1

0 2 1
1 1 1 3
Step 3: Replace all the non-diagonal entries equals 1 with -1
 
3 −1 −1 −1
−1 2 0 −1
A= −1 0

2 −1
−1 −1 −1 3

Step 4: Calculate the cofactor of any entry of A. Let us compute the


cofactor of 3 in the first row and first column
2 0 −1
c11 = 0 2 −1 = 8
−1 −1 3

Hence t(G ) = 8.
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 13 / 30
KRUSKAL’S ALGORITHM
In 1956, the American Mathematician Joseph Kruskal’s discovered the
procedure that will always yield a minimum spanning tree for a weighted
graph. The main idea of Kruskal’s Algorithm is to always choose the edge
with the smallest number (minimum weight) but avoid creating any circuit.
Below is the procedure for finding the minimum spanning tree from a
weighted graph:
1 Choose any edge with the minimum weight in the graph. If there is

more than one, choose any one at random. Mark it using any
designation.
2 Choose any edge with minimum weight from those not yet selected.

If there is more than one, pick any one at random and mark it with
any designation.
3 Continue to choose edges of minimum weight from those not yet

selected except selecting any edge that will create a circuit in the
subgraph until all vertices of the graph have been included. The tree
formed by the edges marked with the designation will give the desired
minimum spanning tree of the weighted graph.
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 14 / 30
Example
Use Kruskal’s Algorithm to find one minimum spanning tree in the
weighted graph below:

Selecting the edge CB followed by BD, DA, AF and FE one of the


minimum spanning tree of the weighted graph above is

Total weight = 1+1+1+2+3=8


Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 15 / 30
PRIM’S ALGORITHM

This is another algorithm, which is also used to find the minimum


spanning trees for a weighted undirected graph. It select a vertex first and
then find an edge with the least weight incident on that vertex.
Here is the procedure for finding the minimum spanning tree from a
weighted graph:
1 Select any vertex, say v1 of the graph G .
2 Select an edge, say e1 of G such that e1 = v1 v2 and v1 6= v2 and e1
has minimum weight among the edges incident on v1 in graph G .
3 Repeat step 2 i.e., select the minimum weighted edge on v2 .
4 Continue this till n − 1 edges have been selected where n is the
number of vertices.
Example
Use Prim’s Algorithm to find one minimum spanning tree of the weighted
graph below:

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 16 / 30


Step 1: Choose any arbitrarily vertex as the root vertex. So we choose E
as the root vertex of the spanning tree.
Step 2: Check the edges incident to the root vertex E and select the one
with least cost. After choosing the root vertex E. We see that the edges
incident to E are EA and EC. So, we choose the edge EA as it lesser than
the other one.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 17 / 30


Step 3: Now, the tree E-7-A is considered as one vertex and we check all
edges incident to A. We select the edge AC as it has the least weight
among the other edges incident to A.

After this, E-A-3-C is formed. Now, we will again considered it as one


vertex and we check the edges incident with C and select the one with the
least weight. In this case we choose the edge CD as it has the least weight.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 18 / 30


After adding vertex D to the spanning tree, we now have two edges
incident to D with the same weight i.e., DB and DF. Thus we can add
either one. But the next step will also yield edge 2 as the least weight.
Hence, we obtained a spanning tree with all the edges of G incleded as
follows:

NOTE: Prim’s Algorithm grows a tree until it becomes the minimum


spanning tree, where as Kruskal’s Algorithm grows a forest trees until this
forest reduces to a single tree (the minumum spanning tree).

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 19 / 30


GREEDY ALGORITHM

The Greedy Algorithm is used for finding an efficient Hamiltonian circuit


(with the cheapest cost) in complete graphs.
Here is the procedure for finding the efficient Hamiltonian circuits in a
complete graph:
1 Choose any vertex as the starting point and travel along the edge
that has the least cost.
2 After arriving at the next vertex, travel along the edge with the least
cost which connects to a vertex that has not yet been visited.
3 Continue until all the vertices of G have been visited.
4 Return to the starting vertex.

Example

Use Greedy Algorithm to find an efficient Hamiltonian circuit in the


complete graph below.
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 20 / 30
Step 1: Choose any vertex as the starting point. So we selected vertex A
as the starting point and we travel along the edge AC which has the least
cost among the other edges incident to A.

Step 2: Now, we look at the edges that are incident to C and travel along
the edge with the least cost. Now, we travel along the edge CD as it has
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 21 / 30
the least cost among the other edges incident to C

Step 3: Now, we see that among the edges incident to D, the edge DE
has the least cost and so we travel along it.

Step 4: Among, the edges incident to E, we will see that EB and EC have
the least cost. But we have already visited the vertex C and so we travel
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 22 / 30
along the edge EB.

Step 5: Then we return to the starting point (i.e., vertex A)

Total cost or weight = 5+4+3+5+9=26


Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 23 / 30
EDGE PICKING ALGORITHM

The Edge picking Algorithm is also used for finding an an efficient


Hamiltonian circuit in a complete graph. Here is the procedure:
1 Select the edge that has the least weight
2 Select the edge of next-smallest weight, as long as it does not formed
a circuit and does not add a third selected edge to a single vertex.
3 Continue until no more edges can be selected. That is, until all the
vertices have been used.
4 Return to the starting vertex.

Example

Use Edge picking Algorithm to find an efficient Hamiltonian circuit in the


previous graph.
Step 1: Select the edge with the least cost. So, we select the edge ED as
it has the least cost among all the edges of G.
Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 24 / 30
Step 2: Select the edge of next-smallest weight. wee select the edge DC.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 25 / 30


Step 3: Select the edge of next-smallest weight. Here, there are 3 edges
of next smallest weight which are CE, EB and CA. But we cannot pick CE
as it will form a circuit. So we choose either EB or AC. Let us choose CA.

Step 4: Select the edge of next-smallest weight. We cannot select the


edge CE as it will formed a circuit. So we select EB.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 26 / 30


Step 5: We return to the starting vertex as we have already visited all the
vertices. So, we return to vertex A

Total cost =3+4+5+5+9=26.


For this labelled, both Algorithms yield the same Hamiltonian circuit. But
this is not always happen.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 27 / 30


SUMMARY/CONCLUSION

In this project we have discussed how to determined whether a graph has


an Euler path or circuit and how to apply Fleury’s Algorithm to find such
path and circuit. Furthermore, we have also seen how to determine the
number of spanning trees using Matrix tree Algorithm and how to apply
Kruskal’s and Prim’s Algorithms to obtain a minimum spanning tree from
a weighted graph. Finally we have seen how to find a Hamiltonian circuit
of least weight from a completed graph using Greedy and Edge picking
Algorithms.

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 28 / 30


References

1 Dr. Eng. Moustafa Reda Abdallah (1435-1436). Discrete


Mathematics.
2 J.A Bondy, U.S.R Murty. Graduate text in Mathematics, Graph
theory.
3 Robin J. Wilson. Introduction to Graph theory (Fourth Edition).

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 29 / 30


THANKS YOU FOR LISTENING

Dahiru Abdurrahman (KFUPM) Short title November 29, 2021 30 / 30

You might also like