You are on page 1of 32

Discrete Mathematics

Lecture 9 - Paths and Circuits

Nurlan Ismailov
nurlan.ismailov@astanait.edu.kz

Astana IT University

June 4, 2020

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 1 / 32
Walks

Many real problems, when translated to questions about graphs, inquire about
the possibility of working through a graph in a particular way. Although our
primary interest is in graphs, the definitions and results of this lecture are
stated for pseudographs, since they apply equally, and with few additional
complications, in the more general setting.

Definition
A walk in a pseudograph is an alternating sequence of vertices and edges,
beginning and ending with a vertex, in which edge is incident with the
vertex immediately preceding it and the vertex immediately following it.
The length of a walk is the number of edges in it.
A walk is closed if the first vertex is the same as the last and otherwise
open.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 2 / 32
Definition
A trail is a walk in which all edges are distinct.
A path is a walk in which all vertices are distinct.
A closed trail is called a circuit.
A circuit in which the first vertex appears exactly twice (at the beginning
and the end) and in which no other vertex appears more than once is a
cycle.

Terms Characteristics of walks

Trail Distinct edges

Path Distinct vertices

Circuit Closed trail

Cycle Closed trail with distinct vertices


(hence distinct edges too)
We note that a path ⇒ a trail, but a trail ; a path.
Nurlan Ismailov nurlan.ismailov@astanait.edu.kz
Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 3 / 32
Example

B D

E F

ABCEF CBD is a walk of length 7 that is neither a trail nor a path.


ABCEF CD is a trail, but not a path.
ABCEF CDBA is a closed walk that is not a circuit.
BCEF CDB is a circuit that is not cycle.
BCDB is a cycle of length 3 (3-cycle).
CEF CBDC is a closed walk which is not a cycle.
Nurlan Ismailov nurlan.ismailov@astanait.edu.kz
Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 4 / 32
Eulerian Circuits

Definition
An Eulerian circuit in a pseudograph is a circuit that contains every vertex
and every edge. A pseudograph is Eulerian if it contains an Eulerian circuit.

B D

E F

The circuit ABCEF CDA is not Eulerian because it does not contain the edge
BD. As we will soon see, this graph possesses no Eulerian circuit; it is not an
Eulerian graph.
Nurlan Ismailov nurlan.ismailov@astanait.edu.kz
Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 5 / 32
The circuit ABCDEF GHF A is not Eulerian since while it encompasses all
vertices, it omits four edges.

However ABCDEF GHF ADBEA is an Eulerian circuit, so the graph is


Eulerian.

H A
B

C
F
G E D

Definition
A pseudograph is connected if and only if there exists a walk between any two
vertices.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 6 / 32
If a graph is connected, then there is actually a path between any two vertices,
not just a walk.
An Eulerian graph must be more than just connected, however, as the graph
in the figure illustrates. The basic difficulty with this graph is that there is
only one edge incident with A. Any circuit that begins at A cannot return to
A without using this edge again, and any circuit that begins at a vertex other
than A and attempts to include all edges, after using the edge BA (in the
direction B to A), has to repeat in route back to the starting back. The
degrees of the vertices play a role in determining whether a graph is Eulerian.
It is not hard to see that the degrees of the vertices of an Eulerian graph must
be even.

B
E
C

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 7 / 32
A criterion to be Eulerian

Theorem 1 (Euler)
A pseudograph (with at least two vertices) is Eulerian if and only if it is
connected and every vertex is even.

Sometimes, instead of finding an Eulerian circuit in a pseudograph, we want


to find an Eulerian trail between two vertices, a trail that passes through every
vertex and includes every edge.

Theorem 2 (Euler)
A pseudograph G possesses an Eulerian trail between two (different) vertices u
and v if and only if it is connected and all vertices except u and v are even.

We leave the proofs of the theorems to students.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 8 / 32
Example

Is the graph below Eulerian?

B D

E F

Answer: No, it is not Eulerian, because not all vertices are even; for example,
deg B = 3.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 9 / 32
Return to Königsberg bridge problem

Now we are ready to answer to the Königsberg bridge problem.


Seven bridges crossed the river, providing links among the four land masses
labeled A, B, C, D in the figure. People wondered if it were possible to start
on one of the land masses, walk over each of the seven bridges exactly once,
and return to the starting point (without getting wet).

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 10 / 32
Answer to Königsberg bridge problem

By means of this graph, the physical problem in transformed into this


mathematical one. Given the graph in the Figure, is it possible to choose a
vertex, then to proceed along the edges one after the other and return to the
chosen a vertex, covering every edge exactly once?
As we see that
deg A = 5,
deg B = deg C = deg D = 3.
Hence, by Eulerian theorem,
it is not Eulerian graph.
Therefore, it is not possible
to choose a vertex, then to
proceed along the edges one
after the other and return to
the chosen a vertex, covering
every edge exactly once.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 11 / 32
Hamiltonian Cycle

An Eulerian circuit passes through every edge of a graph exactly once. Now
we discuss circuits that passes though each vertex of a graph exactly once.
Unlike the situation in Eulerian case, the definitions and results here apply
only to graphs, not a pseudograph.

Definition (Hamiltonian cycle)


A Hamiltonian cycle in a graph is a cycle that contains every vertex of the
graph. A Hamiltonian graph is one with a Hamiltonian cycle.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 12 / 32
Examples

Graph G1 in below is Hamiltonian. The cycle ABCDEA, for instance, is


Hamiltonian.
On the other hand, G2 is not Hamiltonian,

E A B
C C
B
D D E

G1 G2

but how can we convince ourselves of this fact?

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 13 / 32
The proof

Suppose that G2 has a cycle H that contains every vertex. Then H will
contain A, which we note is a vertex of degree 2. Since we cannot enter and
leave A on the same edge (edges of a cycle are distinct), it follows that both
edges incident with A have to be part of H. In particular, edge CA is in H.
The same argument applied to B shows that CB is part of H and, similarly.
CD and CE are in H. All four edges incident with C are part of H. This
situation is impossible, however: since H is a cycle, vertex C can appear only
once unless the cycle begins and ends at C. In either case, since H cannot use
the same edge twice, exactly two edges incident with C can be part of H.

A B
C

D E

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 14 / 32
No criterion to be Hamiltonian

While it is possible to decide precisely which graphs possess Eulerian circuits,


it is noteworthy that there has not yet been found a way to classify
Hamiltonian graphs; in other words, there is no known theorem of the sort
“G is Hamiltonian if and only if . . .”.

There are, however, some properties of cycles that are helpful in trying to find
Hamiltonian cycles and that sometimes allow us to conclude that a particular
graph is not Hamiltonian.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 15 / 32
Properties of cycles in graphs

Suppose H is a cycle in a graph G.


For each vertex v of H, precisely two edges incident with v are in H;
hence, if H is a Hamiltonian cycle of G and a vertex in G has degree 2,
then both edges incident with v must be part of H.
The only cycle contained in H is H itself.

Proof of Property 1. We have in essence, already explained why each


vertex of a cycle is incident with exactly two edges: any vertex (except the
first and last) appears exactly once in a cycle. If the cycle H is Hamiltonian,
then every vertex is in H, so both edges incident with any vertex of degree 2
must be in H. This establishes Property 1.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 16 / 32
The property 2 asserts that, if C is a cycle contained in another cycle H,
C = H. We prove this by contradiction.

Proof of Property 2. Suppose C is a cycle contained in H and C 6= H. Then


there is a vertex y in H that is not in C. Let x be any vertex in C. Since H
contains both x and y, there is a path using edges of H from x to y. Thus, H
contains some edge vw where vertex v is in C, but w is not. See the figure. So
H contains the two edges of C that are incident with v together with the edge
vw. Altogether, there are three edges incident with v that must be part of H.
This contradicts Property 1. Thus H is not a cycle. 

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 17 / 32
Example

Questions
Is this graph Hamiltonian?

Is it True
or False that “The graph is
not Hamiltonian because it
contains the cycle GHIG”?

Answers: False! The graph is Hamiltonian: AF EDIHGCBA is a


Hamiltonian cycle. It is not the entire graph that must not contain a proper
cycle, but any Hamiltonian cycle.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 18 / 32
The Peterson graph

As a deeper
application of the properties of Hamiltonian
graphs described above, we introduce
a famous graph named after the Danish
mathematician Julius Peterson (1839-1910).

We show that this graph is not Hamiltonian.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 19 / 32
The Proof: The Peterson graph is not Hamiltonian
Suppose H is a Hamiltonian cycle.
Then H must contain at least one of the
five edges connecting the outer to the inner
vertices. Since the graph is symmetric, there
is no loss of generality in assuming that AF
is part of H. See the figure. By Property 1,
precisely one of the two edges F H and F I is
in H. Again, by symmetry, we may assume
F H is part of the cycle while F I is not.
Since F I is not in H, but two edges incident
with I must be in H (Property 1), IG and ID are in H. Now precisely one of
the edges GB, GJ is in H.
Suppose first that GB is in and GJ is out. Because precisely two edges
incident with J are in H and JG is not, both JH and JE are part of H. Thus,
CH is out and both BC and CD are in H. At this point, however, H contains
the proper cycle BCDIGB, a contradiction. We conclude that GB cannot be
part of H and hence that GJ is. An argument similar to the one just given
now leads again to the false conclusion that H contains a proper cycle. 
Nurlan Ismailov nurlan.ismailov@astanait.edu.kz
Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 20 / 32
Sufficient condition to be Hamiltonian

The following theorem published by G. A. Dirac in 1952.

Theorem (Dirac)
n
If a graph G has n ≥ 3 vertices and every vertex has degree at least 2, then G
is Hamiltonian.

One can find the proof of the theorem in the main textbook.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 21 / 32
Questions for Self-Study

1. Another Königsberg-type bridge problem.

a. Is it possible to tour the region starting and


finishing in the same area,
having walked over
every bridge exactly once?
Justify your answer.

b. Is it possible to tour the region (with perhaps different starting and


stopping points), having walked over every bridge exactly once?
Justify your answer.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 22 / 32
Questions for Self-Study

2. For which values of n > 1, if any, is Kn Eulerian? Justify your answer.

3. Find a necessary and sufficient condition on natural numbers m and n in


order for Km,n to be Eulerian. Justify your answer.

4. Is Kn Hamiltonian? Justify your answer.

n n−1
5. Show that Dirac’s Theorem is false if 2 is replaced by 2 in its statement.

6. Find a necessary and sufficient condition on natural numbers m and n in


order for Km,n to be Hamiltonian. Justify your answer.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 23 / 32
Graphs and Matrices

Graphs occur with increasing frequency in modern-day problems.

While theoretically, any problem associated with a finite graph is solvable, in


practice, the number of cases to consider is often so large and the time needed
to deal with each case so great than an exhaustive search of all possibilities is
impossible.

Accordingly, the discovery of new graph-based algorithms and ways to


improve efficiency are flourishing areas of mathematical research today.

To write an algorithm that requires the input of a graph, we first must decide
how to code the pertinent information that describes a graph.

For this purpose, the adjacency matrix is commonly used.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 24 / 32
Adjacency matrix

Definition
Let G be a graph with n vertices labeled v1 , v2 , . . . , vn . For each i and j with
1 ≤ i, j ≤ n, define

1 if vi vj is an edge
aij =
0 if vi vj is not an edge.

The adjacency matrix of G is the n × n matrix A = [aij ] whose (i, j) entry is


aij .

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 25 / 32
Examples

Let G be a graph
v1 v2 v3
 
0 0 0 1 0
 0 0 0 1 1 
v4 v5  
 0
then its adjacency matrix A is  0 0 0 0 .

 1 1 0 0 1 
0 1 0 1 0
The adjacency matrix of the complete bipartite graph on the set
V1 = {v1 , v2 } and V2 = {v3 , v4 , v5 } is
 
0 0 1 1 1
 0 0 1 1 1 
 
 1 1 0 0 0 
 
 1 1 0 0 0 
1 1 0 0 0

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 26 / 32
Basic properties of adjacency matrices

Let G be a graph with vertices v1 , v2 , . . . , vn and let A = [aij ] be the adjacency


matrix of G.
The diagonal entries of A are all 0; that is aii = 0 for i = 1, . . . , n.

The adjacency matrix is symmetric, that is, aij = aji for all i, j.

deg vi is the number of 10 s in row i; this is also the number of 10 s in


column i since row i and column i are the same, by symmetry.

For any k ≥ 1, the (i, j) entry of Ak is the number of walks of length k


from vi to vj .

Two graphs are isomorphic if and only if their vertices can be labeled in
such a way that the corresponding adjacency matrices are equal.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 27 / 32
the (i, j) entry in A2
As mentioned, the powers k of an adjacency matrix A have special significance.
Let us consider when k = 2. To understand why the (i, j) entry of A2 is the
number of walks of length 2 between vi and vj in the graph corresponding to
A, remember that this entry is the dot product of row i and column j of A.
Since A contains only 00 s and 10 s, this dot product is just the number of
coordinates in which row i and column j each have a 1.

For example, if row i of A were the vector [0, 0, 1, 0, 1, 1, 0] and the column j
the vector [1, 1, 1, 0, 0, 1, 0], then the dot product (row i)·(row j)=2,
corresponding to the two coordinates (third and sixth) where each vectors has
a 1.

How does it happen that a row and a column have a 1 in the same coordinate?
In our example, row i and column j each have third coordinate 1; this
corresponds to the fact that there is an edge in the graph between vi and v3
and an edge between vj and v3 . There is a walk in the graph from vi to vj
that uses edges, vi v3 vj . The dot product of row i and column j is therefore
the number of walks of length 2 from vi and vj .
The case k > 2 can be justified as in the case k = 2.
Nurlan Ismailov nurlan.ismailov@astanait.edu.kz
Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 28 / 32
Example
Consider the graph
v1 v2 v3

v4 v5

Then
 
1 1 0 0 1

 1 2 0 1 1 

A2 = 
 0 0 0 0 0 .

 0 1 0 3 1 
1 1 0 1 2

The entry (4, 2) of A2 is 1 corresponding to the fact that there is a precisely


one walk of length 2 between v4 and v2 in the associated graph: v4 v5 v2 .
The entry (4, 4) entry of A2 is 3; there are three walks of length 2 from v4
back to v4 , one for each edge incident with v4 .
Nurlan Ismailov nurlan.ismailov@astanait.edu.kz
Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 29 / 32
One more example
The third power of the matrix A is
 
0 1 0 3 1
 1 2 0 4 3 
 
A3 =  0 0 0 0 0 .

 3 4 0 2 4 
1 3 0 4 2

The (4, 5) entry of A3 is 4. Thus, there are four walks of length 3 from v4 to
v5 in the graph.
They are
v4 v5 v2 v5 , v4 v1 v4 v5 , v4 v5 v4 v5 and v4 v2 v4 v5 .

v1 v2 v3

v4 v5

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 30 / 32
Questions for Self-Study

7. What is the adjacency matrix of Kn ?

8. Label the vertices of Km,n so that adjacency matrix has an especially nice
form.

9. Let A be the adjacency matrix of a graph G. Find a necessary and


sufficient conditions for the matrix A2 and A3 to be the adjacency matrix of
some graph G.

10. Reading the section 10.4 Shortest Path Algorithm (about Dijkstra’s
Algorithm and the Floyd-Marshall Algorithm) in the main textbook.

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 31 / 32
The End of Lecture 9

Nurlan Ismailov nurlan.ismailov@astanait.edu.kz


Discrete Mathematics
(Astana IT University)
Lecture 9 - Paths and Circuits June 4, 2020 32 / 32

You might also like