• No results found

Eulerian and Hamiltonian Graphs

In document Applied Combinatorics (Page 99-104)

from traveling on another. This leads to the concept ofmultiple 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 aloop, 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 off a discussion on a graph theory topic with a sentence or two like:

1. In this paper, all graphs will besimple, 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 asimple graph, i.e., no loops or multiple edges. When we want to allow for loops and multiple edges, we will use the termmultigraph. 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 wereallyneeded 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. LetGbe a graph without isolated vertices. We say that Gis eulerianprovided that there is a sequence(x0,x1,x2, . . . ,xt)of vertices fromG, with repetition allowed, so that

1. x0xt;

2. for everyi0,1, . . .t−1,xixi+1is an edge ofG;

3. for every edgeeE, there is a unique integeri with0 ≤ i < t for whiche xixi+1.

Figure 5.12:The bridges of Königsberg

WhenGis eulerian, a sequence satisfying these three conditions is called aneulerian circuit. A sequence of vertices(x0,x1, . . . ,xt)is called acircuitwhen it satisfies only the first 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 finds a graphGthat is eulerian. The output that will be produced is a list of the degrees of the vertices of the graphG followed by a drawing ofG.

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 find a graphHthat isnoteulerian. Again, the output is the list of degrees ofHfollowed by a drawing ofH.

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 first. That would suggest that the non-eulerian graphs outnumber the eulerian graphs. Did you notice anything different 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 graphGis eulerian if and only if it is connected and every vertex has even

degree.

Proof. Clearly, an eulerian graph must be connected. Also, if(x0,x1, . . . ,xt)is an eule- rian circuit inG, then for eachi0,1, . . . ,t−1, we can view the edgexixi+1as exiting

xiand enteringxi+1. The degree of every vertex must be even, since for each vertexx,

the number of edges exitingxequals the number of edges enteringx. Furthermore, each edge incident withxeither exits fromxor entersx.

We now describe a deterministic process that will either (a) find an eulerian circuit, (b) show that the graph is disconnected, or (c) find a vertex of odd degree. The de- scription is simplified by assuming that the vertices inGhave been labelled with the positive integers1,2, . . . ,n, wherenis the number of vertices inG. Furthermore, we takex01.

We launch our algorithm with a trivial circuitCconsisting of the vertexx0 (1).

Thereafter suppose that we have a partial circuitCdefined by(x0,x1, . . . ,xt)withx0

xt1. The edges of the formxixi+1have beentraversed, while the remaining edges in

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

We then choose the least integerifor which there is an edge incident withxithat 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 integeriexists. Setu0xi. We define a sequence(u0,u1, . . . ,us) recursively. Ifj ≥0, set

Nj {y :ujyis an edge inGand has not yet been traversed.}

IfNj ,∅, we takeuj+1as the least positive integer inNj. IfNj ∅, thenj ≥1and we takesjand halt this subroutine.

When the subroutine halts, we consider two cases. Ifu0 , us, thenu0 andus are vertices of odd degree inG. So we are left to consider the case whereu0 us xi. In this case, we simply expand our original sequence(x0,x1, . . . ,xt)by replacing the integerxiby the sequence(u0,u1, . . . ,us). □

As an example, consider the graphGshown inFigure 5.14. Evidently, this graph is connected and all vertices have even degree. Here is the sequence of circuits starting with the trivial circuitCconsisting 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, isnot

eulerian, and thus the citizens could not find 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 graphG(V,E)is said to behamiltonianif there exists a sequence(x1,x2, . . . ,xn) so that

1. every vertex ofGappears exactly once in the sequence;

2. x1xn is an edge ofG; and

3. for eachi1,2, . . . ,n−1,xixi+1is an edge inG.

Such a sequence of vertices is called ahamiltonian cycle.

The first 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 sufficient. Here is one quite well known example, due to Dirac.

Theorem 5.18. IfGis a graph onnvertices and each vertex inGhas at leastn2neighbors,

thenGis hamiltonian.

Proof. Suppose the theorem fails and letnbe the least positive integer for which there exists a graphGonnvertices so that each vertex inGhas at least⌈n/2⌉neighbors, yet there is no hamiltonian cycle inG. Clearly,n ≥4.

Now lett be the largest integer for whichG has a pathP (x1,x2, . . . ,xt) ont vertices. Clearly all neighbors of bothx1 and xt appear on this path. By the pigeon hole principle, there is some integeriwith1 ≤i <tso thatx1xi+1andxixtare edges inG. However, this implies that

C(x1,x2,x3, . . . ,xi,xt,xt−1,xt−2, . . . ,xi+1)

is a cycle of lengthtinG. In turn, this requires⌈n/2⌉ < t < n. But ify is any vertex not on the cycle, then ymust have a neighbor onC, which implies thatGhas a path ont+1vertices. The contradiction completes the proof. □

In document Applied Combinatorics (Page 99-104)