Crossing Each Bridge Once

Draw a graph and this page finds a walk using each edge once, or shows from the odd degrees why none exists.

Made by Claude, an AI model. A graph here is dots (nodes) joined by lines (edges); the number of edges at a node is its degree. The search code is euler.js (MIT) and it runs in your browser. The history section is from memory and marked weaker.

1. Draw a graph

Tap empty space to place a node. Tap a node, then another, to join them; the same pair can be joined twice. Drag a node to move it, or focus it and use the arrow keys. A loop (an edge from a node to itself) comes from the form below.

Edges (press one to remove it):

2. Why the odd nodes decide it

Follow a walk that uses each edge once. Each time it passes through a node it comes in on one edge and leaves on another, so it uses edges at that node two at a time. Only the node where the walk starts and the node where it ends can have an odd number of edges left over. So a walk exists only if the graph has 0 or 2 odd nodes, and the edges must also be one connected piece. That is the degree-parity rule, and it is the closed form the checks below test.

The converse needs a construction, and the page builds one (Hierholzer's method): walk from the start along unused edges until stuck, then splice in the side loops that were left unused. Zero odd nodes gives a closed walk (a circuit); two odd nodes gives an open one that must start at one and finish at the other.

The seven bridges of Königsberg, as I remember the map, join four land areas, here called A to D. Counting from the code: … The sum of the four degrees is …, which is twice the number of bridges (…). The page also lists each possible order of the bridges, … of them, and finds … that form a walk. Taking away one bridge and asking the rule again, … of the … single removals leave a walk (try it: load the example above and press a bridge in the list).

3. The checks, and breaking each once

These run when the page loads. Each compares the rule or the construction with something that does not use the rule.

Running the checks…

CheckGraphsDisagreements

Each check was then broken once on purpose, to see that it can fail:

Deliberate breakFound byDisagreementsResult

Held by construction, so not counted: the degrees add up to twice the number of edges (each edge adds 1 at each end, or 2 at one node for a loop), so the number of odd nodes is always even.

4. History from memory, weaker

None of this section was checked against a source in this run; dates and counts may be off.

5. What is not checked