from traveling on another. This leads to the concept of**multiple edges, i.e., allowing**
for more than one edge between two adjacent vertices. Also, we could have a highway
which leaves a city, goes through the nearby countryside and the returns to the same
city where it originated. This leads to the concept of a**loop, i.e., an edge with both**
end points being the same vertex. Also, we can allow for more than one loop with the
same end point.

Accordingly, authors frequently lead oﬀ a discussion on a graph theory topic with a sentence or two like:

1. In this paper, all graphs will be**simple, i.e., we will not allow loops or multiple**
edges.

2. In this paper, graphs can have loops and multiple edges.

The terminology is far from standard, but in this text, a graph will always be a**simple**
graph, i.e., no loops or multiple edges. When we want to allow for loops and multiple
edges, we will use the term**multigraph. This suggests the question of what we would**
call a graph if it is allowed to have loops but not multiple edges, or if multiple edges are
allowed but not loops. If we*really*needed to talk about such graphs, then the English
language comes to our rescue, and we just state the restriction explicitly!

**5.3 Eulerian and Hamiltonian Graphs**

Graph theory is an area of mathematics that has found many applications in a variety
of disciplines. Throughout this text, we will encounter a number of them. However,
graph theory traces its origins to a problem in Königsberg, Prussia (now Kaliningrad,
Russia) nearly three centuries ago. The river Pregel passes through the city, and there
are two large islands in the middle of the channel. These islands were connected to
the mainland by seven bridges as indicated inFigure 5.12. It is said that the citizens of
Königsberg often wondered if it was possible for one to leave his home, walk through
the city in such a way that he crossed each bridge precisely one time, and end up at
home again. Leonhard Euler settled this problem in 1736 by using graph theory in the
form ofTheorem 5.13. Let**G**be a graph without isolated vertices. We say that **G**is
**eulerian**provided that there is a sequence(*x*0,*x*1,*x*2, . . . ,*xt*)of vertices from**G**, with
repetition allowed, so that

1. *x*0*xt;*

2. for every*i*0,1, . . .*t*−1,*xixi*+1is an edge of**G**;

3. for every edge*e* ∈ *E*, there is a unique integer*i* with0 ≤ *i* < *t* for which*e*
*xixi*+1.

**Figure 5.12:**The bridges of Königsberg

When**G**is eulerian, a sequence satisfying these three conditions is called an**eulerian**
**circuit. A sequence of vertices**(*x*0,*x*1, . . . ,*xt*)is called a**circuit**when it satisﬁes only
the ﬁrst two of these conditions. Note that a sequence consisting of a single vertex is a
circuit. Before proceeding to Euler’s elegant characterization of eulerian graphs, let’s
use SageMath to generate some graphs that are and are not eulerian.

Run the code below. It will execute until it ﬁnds a graph**G**that is eulerian. The
output that will be produced is a list of the degrees of the vertices of the graph**G**
followed by a drawing of**G**.

vertices = 13 edges = 28

g = graphs . RandomGNM ( vertices , edges )

**while** (**not** g . is_eulerian () **or not** g. is_connected () ) :
g = graphs . RandomGNM ( vertices , edges )

**print** g. degree_sequence ()
g. show ()

We encourage you to evaluate the run the code above multiple times, even changing the number of vertices and edges. If it seems to be running a log time, it may be that you have made the number of edges too small, so try increasing it a bit. Do you notice anything about the degrees of the vertices in the graphs produced?

Now let’s try to ﬁnd a graph**H**that is*not*eulerian. Again, the output is the list of
degrees of**H**followed by a drawing of**H**.

vertices = 15 edges = 25

g = graphs . RandomGNM ( vertices , edges )

**while** (g . is_eulerian () **or not** g. is_connected () ) :
g = graphs . RandomGNM ( vertices , edges )

*5.3 Eulerian and Hamiltonian Graphs*
g. show ()

One thing you probably noticed in running this second block of code is that it tended to come back much faster than the ﬁrst. That would suggest that the non-eulerian graphs outnumber the eulerian graphs. Did you notice anything diﬀerent about the degrees of the vertices in these graphs compared to the ones that were eulerian?

The following elementary theorem completely characterizes eulerian graphs. Its proof gives an algorithm that is easily implemented.

**Theorem 5.13.** *A graph***G***is eulerian if and only if it is connected and every vertex has even*

*degree.*

*Proof.* Clearly, an eulerian graph must be connected. Also, if(*x*0,*x*1, . . . ,*xt*)is an eule-
rian circuit in**G**, then for each*i*0,1, . . . ,*t*−1, we can view the edge*xixi*+1as exiting

*xi*and entering*xi*+1. The degree of every vertex must be even, since for each vertex*x*,

the number of edges exiting*x*equals the number of edges entering*x*. Furthermore,
each edge incident with*x*either exits from*x*or enters*x*.

We now describe a deterministic process that will either (a) ﬁnd an eulerian circuit,
(b) show that the graph is disconnected, or (c) ﬁnd a vertex of odd degree. The de-
scription is simpliﬁed by assuming that the vertices in**G**have been labelled with the
positive integers1,2, . . . ,*n*, where*n*is the number of vertices in**G**. Furthermore, we
take*x*01.

We launch our algorithm with a trivial circuit*C*consisting of the vertex*x*0 (1).

Thereafter suppose that we have a partial circuit*C*deﬁned by(*x*0,*x*1, . . . ,*xt*)with*x*0

*xt*1. The edges of the form*xixi*+1have been**traversed, while the remaining edges in**

**G**(if any) have not. If the third condition for an euler circuit is satisﬁed, we are done,
so we assume it does not hold.

We then choose the least integer*i*for which there is an edge incident with*xi*that has
not already been traversed. If there is no such integer, since there are edges that have
not yet been traversed, then we have discovered that the graph is disconnected. So we
may assume that the integer*i*exists. Set*u*0*xi. We deﬁne a sequence*(*u*0,*u*1, . . . ,*us*)
recursively. If*j* ≥0, set

*Nj* {*y* :*ujy*is an edge in**G**and has not yet been traversed.}

If*Nj* ,∅, we take*uj*+1as the least positive integer in*Nj*. If*Nj* ∅, then*j* ≥1and we
take*sj*and halt this subroutine.

When the subroutine halts, we consider two cases. If*u*0 , *us*, then*u*0 and*us* are
vertices of odd degree in**G**. So we are left to consider the case where*u*0 *us* *xi*.
In this case, we simply expand our original sequence(*x*0,*x*1, . . . ,*xt*)by replacing the
integer*xi*by the sequence(*u*0,*u*1, . . . ,*us*). □

As an example, consider the graph**G**shown inFigure 5.14. Evidently, this graph is
connected and all vertices have even degree. Here is the sequence of circuits starting
with the trivial circuit*C*consisting only of the vertex1.

*C*(1)

(1,2,4,3,1) start next from2

(1,2,5,8,2,4,3,1) start next from4

(1,2,5,8,2,4,6,7,4,9,6,10,4,3,1) start next from7

(1,2,5,8,2,4,6,7,9,11,7,4,9,6,10,4,3,1) Done!!
*1*
*5*
*3*
*6*
*4*
*2*
*7*
*8*
*9*
*10*
*11*

**Figure 5.14:**An Eulerian Graph

You should note thatTheorem 5.13holds for loopless graphs in which multiple edges
are allowed. Euler used his theorem to show that the multigraph of Königsberg shown
inFigure 5.15, in which each land mass is a vertex and each bridge is an edge, is*not*

eulerian, and thus the citizens could not ﬁnd the route they desired. (Note that in Figure 5.15there are multiple edges between the same pair of vertices.)

*5.3 Eulerian and Hamiltonian Graphs*

A graph**G**(*V*,*E*)is said to be**hamiltonian**if there exists a sequence(*x*1,*x*2, . . . ,*xn*)
so that

1. every vertex of**G**appears exactly once in the sequence;

2. *x*1*xn* is an edge of**G**; and

3. for each*i*1,2, . . . ,*n*−1,*xixi*+1is an edge in**G**.

Such a sequence of vertices is called a**hamiltonian cycle.**

The ﬁrst graph shown inFigure 5.16both eulerian and hamiltonian. The second is hamiltonian but not eulerian.

*1*
*2*
*3*
*4*
*5*
*6*
*7*
*8*
*9*
*10*

*G*

*1*

*2*

*3*

*4*

*5*

*6*

*7*

*8*

*9*

*10*

*H*

**Figure 5.16:**Eulerian and Hamiltonian Graphs

InFigure 5.17, we show a famous graph known as the Petersen graph. It is not hamil- tonian.

**Figure 5.17:**The Petersen Graph

Unlike the situation with eulerian circuits, there is no known method for quickly de- termining whether a graph is hamiltonian. However, there are a number of interesting conditions which are suﬃcient. Here is one quite well known example, due to Dirac.

**Theorem 5.18.** *If***G***is a graph onnvertices and each vertex in***G***has at least*⌈*n*_{2}⌉*neighbors,*

*then***G***is hamiltonian.*

*Proof.* Suppose the theorem fails and let*n*be the least positive integer for which there
exists a graph**G**on*n*vertices so that each vertex in**G**has at least⌈*n*/2⌉neighbors, yet
there is no hamiltonian cycle in**G**. Clearly,*n* ≥4.

Now let*t* be the largest integer for which**G** has a path*P* (*x*1,*x*2, . . . ,*xt*) on*t*
vertices. Clearly all neighbors of both*x*1 and *xt* appear on this path. By the pigeon
hole principle, there is some integer*i*with1 ≤*i* <*t*so that*x*1*xi*+1and*xixt*are edges
in**G**. However, this implies that

*C*(*x*1,*x*2,*x*3, . . . ,*xi*,*xt*,*xt*−1,*xt*−2, . . . ,*xi*+1)

is a cycle of length*t*in**G**. In turn, this requires⌈*n*/2⌉ < *t* < *n*. But if*y* is any vertex
not on the cycle, then *y*must have a neighbor on*C*, which implies that**G**has a path
on*t*+1vertices. The contradiction completes the proof. □