Whether a walk through a city can cross each of its bridges exactly once depends only on which pieces of land each bridge joins, and the problem is to find a language in which questions like that can be stated precisely and then settled by proof.
The previous lesson ended with the integers as one kind of discrete structure. Networks are another (cities and roads, computers and cables, people and friendships), and in them only what is joined to what matters. The object that keeps exactly that information is a graph. Algorithms and Data Structures shows how to store and search one; this lesson proves what is true of every graph, using two ideas from Proof and Logic: bijections, and equivalence relations, which cut a set into disjoint classes.
Vertices and edges
A simple graph is a finite set of vertices together with a set of edges, where each edge is a two element subset of . Two vertices joined by an edge are adjacent, or neighbours, and the edge is incident to both. A graph is fully described by its edge list: is a triangle with a tail.
The complete graph has vertices and every possible edge, so it has edges: a round robin tournament among football clubs is with edges. The cycle has vertices and edges . The complete bipartite graph has vertices on one side and on the other, and every edge joining the two sides, so edges. A multigraph also allows several edges between the same two vertices (and loops), so that two bridges between the same banks stay two edges. The river problem needs this; otherwise "graph" means simple graph.
Degree and the handshake lemma
The degree of a vertex is the number of edges incident to it. In every vertex has degree ; in every vertex has degree ; in the triangle with a tail the degrees are . A graph in which every vertex has the same degree is -regular.
Handshake lemma. In any graph, .
Count, in two ways, the pairs with an edge incident to the vertex . Vertex is in of them, giving the sum on the left; each edge has two ends and is in two of them, giving . In the triangle with a tail, . At a party, summing the handshakes of every guest counts each handshake twice, hence the name.
Corollary. Every graph has an even number of vertices of odd degree.
The even degrees sum to an even number, so the odd degrees must too, which takes an even number of them. At any party, the number of guests who shook an odd number of hands is even. A degree list with an odd sum belongs to no graph, but an even sum is not enough: no simple graph has degrees , since on four vertices each vertex of degree is adjacent to every other, giving the last two degree at least .
Example. A lab wants to cable computers so that each is connected directly to exactly others. Can it be done? And if each is to be connected to exactly others, how many cables are needed?
With every degree the degree sum would be , which is odd, but it must equal , so no such network exists. With every degree the sum is , so cables, and a ring joining each computer to the two nearest on either side achieves it.
Now you. A graph has edges and every vertex has degree . How many vertices does it have? Could a graph have exactly vertices, all of degree ?
Answer
The degree sum is , and it is also , so . For vertices of degree the sum would be , which is odd, so no such graph exists.
Isomorphism
The edge list draws as a five pointed star, yet renaming as turns it into exactly . Two graphs and are isomorphic if there is a bijection from the vertices of to the vertices of such that is an edge of exactly when is an edge of . It is a renaming, and isomorphic graphs are, for every question here, the same graph.
Showing two graphs are isomorphic takes one bijection, checked edge by edge. Showing they are not means ruling out all bijections at once, and the tool is an invariant, a property every isomorphism preserves: the numbers of vertices and edges, the list of degrees (neighbours of go one to one onto neighbours of ), the number of triangles. If one invariant differs, the graphs are not isomorphic; if the ones you tried agree, nothing follows.
Example. The prism has vertices and edges forming the triangles and together with . Show that is not isomorphic to .
The obvious invariants agree: both graphs have vertices and edges, and both are -regular. The prism contains a triangle, . The graph contains none: every edge crosses from one side to the other, so any closed route alternates sides and has even length, and a triangle would need three. An isomorphism would carry the prism's triangle to a triangle in , so no isomorphism exists.
Now you. Let be the hexagon on vertices with the extra edge , and let be with the extra edge . Check that the vertex counts, edge counts and degree lists agree, then show that and are not isomorphic.
Answer
Both have vertices and edges, and both have degrees . The graph contains the triangle . The graph has none: no two neighbours of any vertex are adjacent (those of are , those of are ). So they are not isomorphic.
Walks, paths and connectedness
A walk is a sequence of vertices in which each consecutive pair is an edge; it has length , the number of edges used, and it is closed if . A trail is a walk that uses no edge twice, and a path is a walk that repeats no vertex. A cycle is a closed walk of length at least whose vertices are distinct apart from the return to the start.
A walk from to always contains a path from to : in a shortest such walk, a repeat with could be cut out to leave a shorter walk, so there is none.
Write when there is a walk from to . This is an equivalence relation: reflexive by the walk of length , symmetric because a walk read backwards is a walk, and transitive because a walk from to followed by one from to is a walk from to . Two paths joined end to end may meet and stop being a path, which is why the relation uses walks.
The equivalence classes of are the connected components of the graph. Equivalence classes partition a set, so every vertex lies in exactly one component, and no edge joins two components, since its ends are related. A graph is connected if it has exactly one component. The graph with edges on vertices has three components, , and .
Deleting an edge that lies on a cycle never disconnects a graph. If lies on a cycle, the rest of the cycle is a path from to , and any walk that used the edge can take that detour instead.
The bridges of Königsberg
Königsberg, in Prussia (now Kaliningrad), stood where the river Pregel flows round the island of Kneiphof, and seven bridges joined its four land masses. Could a walk cross every bridge exactly once? Leonhard Euler answered in a paper presented to the St Petersburg Academy in 1735 and printed in its volume for 1736, Solutio problematis ad geometriam situs pertinentis.
Euler labelled the island , the north and south banks and , and the eastern land between the two arms of the river . Two bridges joined to , two joined to , and one each joined to , to and to . With a vertex per land mass and an edge per bridge, this multigraph has degrees
and the handshake lemma checks the count: .
Euler's argument was a count. A route crossing all seven bridges passes through a sequence of eight land masses. A land mass with bridges, odd, must appear in that sequence times, since every visit except possibly the first or last uses up two of its bridges. So appears times and each of , , appears times, which is appearances in a sequence of . No such walk exists. Euler saw that only the parity of the degrees mattered and stated the general rule, but the proof that the right parities guarantee a walk came 137 years later.
Euler's theorem
An Euler trail uses every edge of the graph, and an Euler circuit is a closed one.
Theorem. A connected multigraph has an Euler circuit exactly when every vertex has even degree. It has an Euler trail that is not closed exactly when it has exactly two vertices of odd degree, and then every such trail starts at one of them and ends at the other.
Necessity. Each pass of an Euler circuit through a vertex arrives along one edge and leaves along another, and the first departure pairs with the final arrival. Every edge is used once, so the edges at each vertex split into pairs and every degree is even. On a trail from to the first edge at and the last at are left unpaired, so exactly and are odd. Königsberg, with four odd vertices, has neither.
Sufficiency. Suppose every degree is even. Start at a vertex and walk, never reusing an edge, until stuck. Arriving at any , the walk has used an odd number of edges at (a pair per earlier pass plus the one just used), and is even, so it can leave again. So it gets stuck only at , as a closed trail . If misses some edges, some vertex of has an unused edge, since otherwise nothing would join to the unused edges and the graph would be disconnected. The unused edges still have even degree at every vertex, because used an even number at each, so the same argument builds a closed trail from out of them. Splice it in: follow to , go round , finish . The closed trail is longer, and repeating uses every edge. This is Carl Hierholzer's argument, published in 1873, two years after his death.
For two odd vertices and , add a new edge (a multigraph allows it). Every degree is now even, so there is an Euler circuit, and deleting the new edge from it leaves an Euler trail between and .
Example. Find an Euler circuit of .
Every degree is , so one exists. Start at and walk until stuck. Vertex has unused edges, so walk from it: . Splice at to get . The edges remain, forming the closed trail , and vertex is on the circuit, so splice at :
That is ten edges, all different, and has .
Now you. German children draw das Haus vom Nikolaus in one stroke without lifting the pen. It is the graph with edges : a square with both diagonals and a roof. Where must the drawing start, and what is one way to draw it?
Answer
The degrees are , , , , . Exactly two are odd, so an Euler trail exists and it must start at or and end at the other. One is , which uses all eight edges once.
Hamilton's question
Change one word: instead of every edge once, ask for a cycle through every vertex once. Such a cycle is a Hamilton cycle, after William Rowan Hamilton, who in 1857 invented the icosian game: find a route along the edges of a dodecahedron through all twenty of its corners, returning to the start. He sold it to a London games maker in 1859 for £25. The puzzle is not hard, but the question behind it has never been answered as Euler answered his.
Euler's criterion is one pass over the degrees. Deciding whether a graph has a Hamilton cycle is NP-complete (one of Richard Karp's 1972 list), so no efficient test is known, and finding one would settle the P versus NP problem. What exists instead are sufficient conditions.
Dirac's theorem (1952). A simple graph with vertices in which every vertex has degree at least has a Hamilton cycle.
The bound cannot be lowered. Take , with vertices and smallest degree , just below . A cycle alternates sides, so it visits equally many vertices on each, and cannot visit all on the larger side. The condition is also far from necessary: is itself a Hamilton cycle, with every degree .
Cycles are where the difficulty lives, and they are also what a connected graph can spare: since deleting an edge on a cycle never disconnects a graph, any connected graph can be stripped, one cycle edge at a time, to a connected graph with no cycles at all. Those are the simplest connected graphs, and the next lesson studies them as trees.