157. Special types of circuits
157.1 Definition: Eulerian circuit
An Eulerian circuit is a circuit in a graph which contains each edge exactly once. It need not be a cycle; in other words, nodes may be repeated, but not edges.
A graph need not have an Eulerian circuit. For example, the graph in Figure (152.1) has no Eulerian circuit. There is a simple criterion for whether a graph has an Eulerian circuit:
157.2 Theorem
A connected graph $G$ has an Eulerian circuit if and only if the degree of every node is even.
Proof Suppose $G$ has an Eulerian circuit. As you go around the circuit, you have to hit every edge exactly once. Every time you go through a node, you must therefore leave by a different edge from the one you entered. So for each node $p$, you can divide the edges incident to $p$ into two groups: those you enter $p$ on and those you leave $p$ on. Since you enter and leave $p$ the same number of times, these two groups of edges must have the same number of elements. Thus the number of edges incident on $p$ is even.
Now for the converse: suppose every node of $G$ has even degree. To construct an Eulerian circuit, pick a node $p$. If that is the only node in $G$ you are finished. Otherwise, there is an edge on $p$. Travel along that edge to some node $q$ and mark the edge so you won’t use it again. Because there are an even number of edges incident on $q$, there is an unmarked edge. Leave on the edge and repeat the process until you arrive at $p$ again.
This process will produce a circuit containing $p$. No edge can be repeated because you are marking the ones you use, and because of finiteness you have to return to $p$ sometime. However, the circuit may not pass over every edge. If it does not, there is an unmarked edge $e$ incident on some node $q$ already in your circuit, because $G$ is connected. Start with that node and that edge and repeat the process, continuing until you return to $q$. This will give another circuit containing $q$. Note that the second circuit may hit nodes of the first circuit, but there will always be an unmarked edge to leave on because each node in the first circuit has even degree and an even number of marked edges. You now can put these two circuits together into a big circuit — go around the first circuit starting at $p$ until you get to $q$, go around the second circuit until you return to $q$, and then continue around the first circuit until you get back to $p$. If you still don’t hit all the edges, you can repeat this process a second time, and so on until all the edges are used up. The result will be an Eulerian circuit.
This problem was first solved by Leonhard Euler, who was asked whether it was possible to walk around the city of Königsberg (then in Prussia, now in Russia and called Kaliningrad) in such a way that you could traverse each of its seven bridges exactly once. The arrangement of bridges in Euler’s time is represented by the left graph in Figure (152.1), page 232 (each edge represents a bridge), which clearly has no Eulerian circuit since in fact none of its nodes has even degree.
157.2.1 Exercise For which integers $n$ does $K_{n}$ have an Eulerian circuit?
157.2.2 Exercise For which integers $m$ and $n$ does $K_{m,n}$ have Eulerian circuit?
157.3 Definition: Hamiltonian circuit
A Hamiltonian circuit in a graph is a circuit which hits each node exactly once.
157.3.1 Fact Such a graph must be connected (why?).
157.3.2 Remark Our main purpose in mentioning Hamiltonian circuits is to contrast their theory with that of Eulerian circuits: there is no known simple criterion to determine whether a graph has a Hamiltonian circuit or not. The problem is computationally difficult in general, although for special classes of graphs the question can be answered more easily (Problems 157.4.5 and 157.3.3).
157.3.3 Exercise For which integers $m$ and $n$ does $K_{m,n}$ have a Hamiltonian circuit?
157.4 Exercise set
Exercises 157.4.1 through 157.4.3 concern the graphs in Table 152.1, page 231.
157.4.1 Give the diameter of each graph. (Answer on page 251.)
157.4.2 Which of the graphs has an Eulerian circuit? (Answer on page 252.)
157.4.3 Which of the graphs has a Hamiltonian circuit? (Answer on page 252.)
157.4.4 Give examples of:
a) A graph which has an Eulerian circuit but not a Hamiltonian circuit. b) A graph which has a Hamiltonian circuit but not an Eulerian circuit.
157.4.5 For which integers $n$ does $K_{n}$ have a Hamiltonian circuit?
Pages 237–239 of the book (PDF).