University Center of Si El’Houès Barika
Department of Mathematics and Computer Science
Graph theory
nd
2 year computer science student
Chapter 1: Eulerian and Hamiltonian Graphs
Pre-requirements:
• Mathematics basics
• Algorithmic basics
Objectives:
• Determine whether a graph has an Euler path and/ or an Euler circuit
• Add edges to a graph to create an Euler circuit if one doesn’t exist
• Identify whether a graph has a Hamiltonian path and/ or Hamiltonian circuit
Contents
Introduction: ......................................................................................................................................... 1
I. Euler Graph:.................................................................................................................................. 2
II. Hamiltonian graph: ...................................................................................................................... 4
Introduction:
There are many games and puzzles which can be analyzed by graph theoretic concepts. In
fact, the two early discoveries which led to the existence of graphs arose from puzzles, namely, the
Konigsberg Bridge Problem and Hamiltonian Game, and these puzzles also resulted in the special
types of graphs, now called Eulerian graphs and Hamiltonian graphs. Due to the rich structure of
these graphs, they find wide use both in research and application.
Dr.Belferdi Wassila 2024/2025 1
I. Euler Graph:
The following problem, often referred to as the
bridges of Konigsberg problem, was first solved by
Euler in the eighteenth century.
The problem was rather simple the town of
Konigsberg consists of two islands and seven
bridges. Is it possible, by beginning anywhere and
ending anywhere, to walk through the town by
crossing all seven bridges but not crossing any
bridge twice?
We will first present some definitions and then present a theorem that Euler used to show that it
is in fact impossible to walk through the town and traverse all the edges only once.
a) Definitions
Eulerian trail (or path) :
Is a trail (or a path) that visits every edge (or directed edge) of the graph once and only once (no
repeats). Being a trail (or a path), it does not have to return to the starting vertex.
Example
In this graph, there are several Euler trails.
One such path is CABDCB.
Euler circuit (or cycle) :
An Euler circuit (or cycle) is a circuit (cycle) that uses every edge (directed edge) in a graph with no
repeats. Being a circuit (or a cycle), it must start and end at the same vertex.
Example
The graph below has several possible Euler cycles such as: ADEACEFCBA and AECABCFEDA.
Euler graph
A graph containing an Euler circuit (or cycle) is called an Euler graph. In other words, if some
circuit (or cycle1 ) in a graph contains all the edges of the graph, then the graph is called an Euler
graph.
1 closed path (or chain)
2
Dr.Belferdi Wassila 2024/2025
A non-Eulerian graph 𝑮 is semi-Eulerian if there exists a trail (or a path) containing every
edge of 𝑮.
Example: The following graphs are Eulerian, semi-Eulerian and non-Eulerian, respectively.
Theorem (Euler’s chain and cycle)
✓ A graph will contain an Euler chain if it contains at most two vertices of odd degree.
✓ A graph will contain an Euler cycle if all vertices have even degree.
Example
In this graph:
▪ Vertices A and C have degree 4.
▪ B is of degree 2, D is degree 3, and E is degree 1.
This graph contains two vertices with odd degree (D and E) and
three vertices with even degree (A, B, and C), so Euler’s theorems
Theorem (Euler)
✓ A connected graph 𝑮 is an Euler graph if and only if all vertices of 𝑮 are of even degree.
✓ A connected graph is semi-Eulerian if and only if it has exactly two vertices of odd
degree.
Note (Euler in Digraph)
✓ The existence of an Eulerian circuit depends on the outdegree and indegree of the each
vertex which must be as many ingoing edges as there are outgoing edges.
✓ A strongly connected multi-digraph admits an Eulerian circuit if and only if 𝑑𝑒𝑔+ ሺ𝑣ሻ =
𝑑𝑒𝑔− ሺ𝑣ሻ for any vertex.
Theorem (Euler path)
✓ A strongly connected multi-digraph admits an Eulerian path from 𝒖 to 𝒗 if and only if:
𝑑𝑒𝑔+ ሺ𝑢ሻ = 𝑑𝑒𝑔− ሺ𝑢ሻ + 1
𝑑𝑒𝑔+ ሺ𝑣ሻ = 𝑑𝑒𝑔− ሺ𝑣ሻ − 1
𝑑𝑒𝑔+ ሺ𝑠ሻ = 𝑑𝑒𝑔− ሺ𝑠ሻ for any other vertex.
Dr.Belferdi Wassila 2024/2025 3
tell us this graph has an Euler trail (path), but not an Euler circuit (cycle).
II. Hamiltonian graph:
A similar problem is to determine whether there exists a cycle passing exactly once through
each vertex of 𝑮. Such a cycle is a Hamiltonian cycle and 𝑮 is a Hamiltonian graph.
A non-Hamiltonian graph 𝑮 is semi-Hamiltonian if there exists path passing through every
vertex.
Example
These graphs are:
▪ Hamiltonian,
▪ Semi-Hamiltonian
▪ Non-Hamiltonian.
a) Hamiltonian path:
▪ Removing any one edge from a Hamiltonian cycle, results a path called a Hamiltonian
path.
▪ A Hamiltonian path in a graph 𝑮 traverses every vertex of 𝐺.
▪ In considering the existence of a Hamiltonian cycle (or path), we need only consider simple
graphs. This is because a Hamiltonian cycle (or path) traverses every vertex exactly once.
Hence it cannot include a self-loop or a set of parallel edges.
▪ A general graph may be made simple by removing parallel edges and self-loops before
looking for a Hamiltonian circuit in it.
Theorem (Ore, 1960)
If 𝑮 is a simple graph with 𝒏 ሺ𝒏 ≥ 𝟑ሻ vertices, and if 𝒅𝒆𝒈ሺ𝒗ሻ + 𝒅𝒆𝒈ሺ𝒘ሻ ≥ 𝒏 for each
pair of non-adjacent vertices 𝒗 and 𝒘, then 𝑮 is Hamiltonian.
Corollary (Dirac, 1952).
If 𝑮 is a simple graph with 𝒏 ሺ𝒏 ≥ 𝟑ሻ vertices, and if 𝒅𝒆𝒈ሺ𝒗ሻ ≥ 𝒏/𝟐 for each vertex
𝒗, then 𝑮 is Hamiltonian.
Note:
✓ For a connected graph to be Eulerian there is a necessary and sufficient conditions.
However, for Hamiltonian graphs, the finding of such a characterization is one of the
major unsolved problems of graph theory.
✓ We do not know any necessary and sufficient condition of existence of cycles (chains,
circuits or paths) Hamiltonians, valid for all graphs. In fact, most existing theorems have
the form, 'if G has enough edges, then G is Hamiltonian'.
✓ Probably the most celebrated of these is the Dirac's theorem. We deduce it from the
following more general result of Ore’s theorem.
Dr.Belferdi Wassila 2024/2025 4
Traveling-salesman problem
A problem closely related to the question of Hamiltonian circuits is the traveling-salesman problem,
stated as follows:
A salesman is required to visit a number of cities during a trip. Given the distances between the
cities, in what order should he travel so as to visit every city precisely once and return home, with
the minimum distance traveled?
Representing the cities by vertices and the roads between them by edges, we get a graph, with every
edge associated a real number (the distance in miles).
This graph has numerous Hamiltonian circuits, and we are to pick the one that has the smallest
sum of distances (or weights).
Theoretically, the problem of the traveling salesman can always be solved by enumerating all ሺ𝑛 −
𝑙ሻ!/2 Hamiltonian circuits, calculating the distance traveled in each, and then picking the shortest
one.
However, for a large value of 𝑛, the labor involved is too great even for a digital computer. No
efficient algorithm for problems of arbitrary size has yet been found, although many attempts have
been made.
Dr.Belferdi Wassila 2024/2025 5