The problem (1736). Königsberg sat on both banks of the Pregel river, with two islands connected by seven bridges. Can one walk through the city crossing every bridge exactly once?

Euler proved: no — and in doing so founded graph theory.

Euler’s argument

Reduce the city to a graph: the four land masses are vertices, the seven bridges are edges.

        A
       /|\
      / | \
     C--B--C          (multi-edges: two bridges between some pairs)
      \ | /
        D

The degrees are four odd-degree vertices.

Every time the walk enters a land mass it must leave again, so each visit uses two bridges. A land mass with odd degree must therefore be the start or the end of the walk.

A walk has only two endpoints, so at most two vertices may have odd degree.

Königsberg has four. Impossible. ∎

The general theorem

For a connected graph (ignoring isolated vertices):

Condition
Eulerian circuit (closed)every vertex has even degree
Eulerian path (open)exactly two vertices have odd degree
Neitherfour or more odd-degree vertices

By the handshake lemma the number of odd-degree vertices is always even, so “exactly two” is the only open case. See Eulerian Path and Circuit.

For directed graphs: a circuit requires everywhere; a path allows one vertex with (the start) and one with the reverse.

Constructing the tour

Hierholzer’s algorithm finds an Eulerian circuit in : walk until stuck, then splice in detours from vertices with unused edges.

// iterative Hierholzer with a per-vertex edge pointer
while (!st.empty()) {
    int u = st.back();
    while (it[u] < (int)adj[u].size() && used[adj[u][it[u]].id]) it[u]++;
    if (it[u] == (int)adj[u].size()) { circuit.push_back(u); st.pop_back(); }
    else { auto [v, id] = adj[u][it[u]++]; used[id] = true; st.push_back(v); }
}

The it[] pointer is essential — without it the algorithm degrades to .

What Euler’s argument teaches

It is the archetype of an invariant / parity impossibility proof:

  1. Identify a quantity every legal move preserves or changes predictably (here: each visit consumes two edge-ends).
  2. Show the goal state is incompatible with it.
  3. Conclude impossibility — without any search.

The same move proves the 15-puzzle unsolvable for odd permutations, the mutilated chessboard untileable, and the closed knight’s tour impossible on odd boards.

The modern descendants

ProblemRelation
Eulerian paththe direct generalisation,
Chinese postmantraverse every edge at least once, minimising distance — pair up odd vertices with a min-weight matching
De Bruijn sequencesan Eulerian circuit in the de Bruijn graph
Genome assemblyEulerian path in a de Bruijn graph of reads
Hamiltonian paththe vertex analogue — NP-complete, in sharp contrast
Route inspection, snow ploughing, mail deliveryChinese postman in practice

The Eulerian/Hamiltonian contrast is one of the most instructive pairs in the subject: “use every edge once” has a local degree characterisation and a linear algorithm; “use every vertex once” has neither.

The Chinese postman, concretely

If the graph is Eulerian, the answer is the total edge weight. Otherwise, find the odd-degree vertices (an even number, say ), compute shortest paths among them, find a minimum-weight perfect matching on those , and duplicate the matched paths:

With , a bitmask DP does the matching; otherwise Blossom.

The historical note

Euler’s 1736 paper is generally regarded as the first work in graph theory and in topology — he explicitly noted that the answer depends only on the connection structure, not on distances or geometry. Two of Königsberg’s bridges were destroyed in 1944, and today the city (Kaliningrad) has five bridges and exactly two odd-degree vertices, so an Eulerian path now exists.

See also: Eulerian Path · Hierholzer · Parity Arguments