Skip to content
Family Table Math
Auto

The Chinese Postman Problem

A mail carrier has to walk along every street on their route and return to the post office. A snowplough, a street sweeper and a road inspector have the same job. What is the shortest route that covers every edge of a weighted graph at least once and returns to the start? This is the Chinese postman problem (also called the route inspection problem), first posed by the Chinese mathematician Kwan Mei-Ko in 1962.

If every vertex of a connected graph is even, the graph has an Eulerian circuit: a closed route using every edge exactly once. That route is clearly the shortest possible, so

shortest route=total weight of all the edges\text{shortest route} = \text{total weight of all the edges}

At an odd vertex, the route can’t pair every arrival with a departure along a new edge, so some edges at that vertex must be travelled twice. Repeating an edge is the same as adding a copy of it to the graph. We want to add copies so that every vertex becomes even, as cheaply as possible.

Adding copies along a path from one odd vertex to another changes the degree of those two end vertices by 11 (making them even) and of every vertex in between by 22 (keeping them even). So the cheapest fix is to pair up the odd vertices and repeat the shortest path between each pair. The new graph has an Eulerian circuit, and that circuit is the postman’s route.

  1. List the odd vertices. If there are none, the answer is the total weight.
  2. List every way of pairing them up.
    • With 22 odd vertices, say X and Y, there’s only one pairing: XY.
    • With 44 odd vertices W, X, Y, Z, there are three: WX and YZ; WY and XZ; WZ and XY.
  3. For each pairing, find the shortest path between each pair (by inspection, checking possible routes) and add the lengths.
  4. Choose the pairing with the smallest total. Repeat the edges on those shortest paths.
  5. Shortest route length == total weight of all edges ++ the smallest pairing total. Find an actual route as an Eulerian circuit of the graph with the repeated edges added.

The IB course uses graphs with up to four odd vertices.

A variation: start and finish at different vertices

Section titled “A variation: start and finish at different vertices”

Sometimes the route doesn’t have to return to its start. Then two odd vertices can be the start and finish, and they don’t need pairing.

  • With 22 odd vertices: start at one, finish at the other. Nothing is repeated, so the length is just the total weight.
  • With 44 odd vertices: you still pair two of them. Repeat the single shortest of the six possible odd-to-odd paths, and start and finish at the other two odd vertices.

A road inspector must drive along every road in a network and return to the depot at A. The roads, with lengths in km, are AB 66, AC 88, BC 33, BD 77, CD 55, CE 99, DE 44, DF 66 and EF 55. Find the length of the shortest inspection route.

Solution. Total length of all roads:

6+8+3+7+5+9+4+6+5=53 km6 + 8 + 3 + 7 + 5 + 9 + 4 + 6 + 5 = 53 \text{ km}

Degrees: A 22, B 33, C 44, D 44, E 33, F 22. The odd vertices are B and E, so there’s one pairing: BE.

Shortest path from B to E (there’s no direct road): B–D–E is 7+4=117 + 4 = 11, B–C–E is 3+9=123 + 9 = 12, and B–C–D–E is 3+5+4=123 + 5 + 4 = 12. The shortest is B–D–E, 1111 km.

Repeat BD and DE. The shortest route is 53+11=6453 + 11 = 64 km.

A weighted graph with vertices A to F and edges AB 4, AC 6, AD 9, BC 5, BE 8, CD 3, CE 7, DF 5, EF 4. The odd vertices A, B, D and E are highlighted. 4 6 9 5 8 3 7 5 4 A B C D E F
The odd vertices A, B, D and E are highlighted.

Find the shortest route that travels along every edge of the graph above at least once and returns to its starting point. Write down one such route starting at A.

Solution. Total weight: 4+6+9+5+8+3+7+5+4=514 + 6 + 9 + 5 + 8 + 3 + 7 + 5 + 4 = 51.

Degrees: A 33, B 33, C 44, D 33, E 33, F 22. There are four odd vertices: A, B, D, E.

Find the shortest path between each pair of odd vertices:

PairShortest pathLength
ABA–B4
DED–F–E9
ADA–D (or A–C–D)9
BEB–E8
AEA–B–E12
BDB–C–D8

Now compare the three pairings:

PairingTotal
AB and DE4+9=134 + 9 = 13
AD and BE9+8=179 + 8 = 17
AE and BD12+8=2012 + 8 = 20

The best pairing is AB and DE, so repeat AB, DF and FE. The shortest route has length

51+13=6451 + 13 = 64
The same graph with the edges AB, DF and FE repeated (drawn as dashed orange copies beside the originals). Now every vertex has even degree. 4 6 9 5 8 3 7 5 4 A B C D E F
Repeating AB, DF and FE makes every vertex even.

With the repeats, every vertex has degree 44, so there’s an Eulerian circuit. One route from A:

A–B–A–C–B–E–F–E–C–D–F–D–A\text{A–B–A–C–B–E–F–E–C–D–F–D–A}

Check: it uses 1212 edges (the 99 original edges plus the 33 repeats), and its length is 6464.

For the graph in Example 2, the route may now start and finish at different vertices. Find the length of the shortest route, and where it must start and finish.

Solution. Two of the odd vertices can be the start and finish; the other two must be joined by a repeated shortest path. From the table in Example 2, the shortest odd-to-odd path is AB, length 44.

So repeat AB, and start at D and finish at E (or the reverse). The shortest route is

51+4=5551 + 4 = 55

Repeating the direct edge when a shorter path exists. In Example 2, D and E aren’t even adjacent, and in other graphs the direct edge between two odd vertices can be longer than a route through another vertex. Always check the alternatives.

Checking only one pairing. With four odd vertices there are three pairings, and the best one isn’t always the one with the single shortest path. Work out all three totals.

Forgetting the total weight. The answer is the total of all the edges plus the repeated paths, not just the repeats.

Pairing even vertices. Only the odd vertices need fixing. Vertices in the middle of a repeated path stay even.

Mixing up the closed and open versions. If the route must return to its start, pair all the odd vertices. If it can finish elsewhere, two odd vertices become the ends and only one pair gets a repeated path.

1. (Warm-up) A graph has edges AB 55, BC 77, CA 66, CD 44, DE 33 and EC 88. Find the length of the shortest closed route that travels every edge.

Solution

Degrees: A 22, B 22, C 44, D 22, E 22. All even, so there’s an Eulerian circuit and nothing needs repeating:

5+7+6+4+3+8=335 + 7 + 6 + 4 + 3 + 8 = 33

2. (Warm-up) A graph has exactly four odd vertices, P, Q, R and S. List all the possible pairings.

Solution

PQ and RS; PR and QS; PS and QR. (P must be paired with one of the other three, and that decides the second pair.)

3. (Warm-up) A connected graph has total weight 4040. Its only odd vertices are X and Y, and the shortest path between them has length 44. What is the length of the shortest closed route that travels every edge?

Solution

Repeat the shortest X–Y path: 40+4=4440 + 4 = 44.

4. (Core) A park has paths PQ 66, PR 99, QR 44, QS 88, RS 55, RT 77 and ST 33 (in hundreds of metres). A ranger must walk every path and return to the start. Find the length of the shortest route, and which path(s) are walked twice.

Solution

Total: 6+9+4+8+5+7+3=426 + 9 + 4 + 8 + 5 + 7 + 3 = 42.

Degrees: P 22, Q 33, R 44, S 33, T 22. Odd vertices Q and S.

Shortest Q–S path: direct QS is 88; Q–R–S is 4+5=94 + 5 = 9. So repeat QS.

Shortest route: 42+8=5042 + 8 = 50 hundred metres, which is 55 km, with path QS walked twice.

5. (Core) A graph has edges AB 33, AC 88, BC 44, BD 77, CD 22, CE 55 and DE 77. Find the length of the shortest closed route that travels every edge, and say which edges are repeated.

Solution

Total: 3+8+4+7+2+5+7=363 + 8 + 4 + 7 + 2 + 5 + 7 = 36.

Degrees: A 22, B 33, C 44, D 33, E 22. Odd vertices B and D.

Shortest B–D path: direct BD is 77, but B–C–D is 4+2=64 + 2 = 6. So repeat BC and CD.

Shortest route: 36+6=4236 + 6 = 42.

6. (Core) A graph has edges AB 1010, AC 44, BC 55, BD 33, CD 88, AE 66, CE 77 and DE 99. Find the length of the shortest closed route that travels every edge.

Solution

Total: 10+4+5+3+8+6+7+9=5210 + 4 + 5 + 3 + 8 + 6 + 7 + 9 = 52.

Degrees: A 33, B 33, C 44, D 33, E 33. Odd vertices A, B, D, E.

Shortest paths: AB 99 (A–C–B, shorter than the direct 1010), DE 99, AD 1212 (A–C–D or A–C–B–D), BE 1212 (B–C–E or B–D–E), AE 66, BD 33.

PairingTotal
AB and DE9+9=189 + 9 = 18
AD and BE12+12=2412 + 12 = 24
AE and BD6+3=96 + 3 = 9

Repeat AE and BD. Shortest route: 52+9=6152 + 9 = 61.

7. (Core) For the graph in Question 6, the route may start and finish at different vertices. Find the length of the shortest route that travels every edge, and where it starts and finishes.

Solution

Repeat only the single shortest odd-to-odd path, which is BD (33), and start and finish at the other two odd vertices, A and E.

Shortest route: 52+3=5552 + 3 = 55, starting at A and finishing at E (or the reverse).

8. (Challenge) In the graph of Example 2, the weight of edge AB is changed from 44 to xx, where x>0x \gt 0. For which values of xx is pairing AB and DE still the best choice? Find the length of the shortest closed route in terms of xx for those values.

Solution

The shortest A–B path is now the smaller of xx and A–C–B =6+5=11= 6 + 5 = 11. Compare the three pairings when x<11x \lt 11:

  • AB and DE: x+9x + 9.
  • AD and BE: B–E is still 88, and A–D is the smaller of 99 and A–B–C–D =x+8= x + 8. The total is the smaller of 1717 and x+16x + 16.
  • AE and BD: B–D is still 88 (B–C–D), and A–E is the smaller of 1313 (A–C–E) and x+8x + 8 (A–B–E). The total is the smaller of 2121 and x+16x + 16.

Since x+9<x+16x + 9 \lt x + 16 always, AB and DE is best exactly when x+9<17x + 9 \lt 17, that is, x<8x \lt 8. (At x=8x = 8 it ties with AD and BE; for x>8x \gt 8, AD and BE is better.)

For 0<x<80 \lt x \lt 8: total weight is 47+x47 + x, so the shortest route is

(47+x)+(x+9)=56+2x(47 + x) + (x + 9) = 56 + 2x

Check: x=4x = 4 gives 6464, matching Example 2.

9. (Challenge) Explain why, in the Chinese postman algorithm, the repeated edges should form shortest paths joining the odd vertices in pairs, and why the resulting route is the shortest possible.

Solution

Think of the repeated edges as extra copies added to the graph. A closed route covering every edge exactly once in the new graph exists only if every vertex is even. The extra copies must therefore add an odd number of edges at each odd vertex and an even number at each even vertex. Any set of extra edges with this property can be split into trails that join the odd vertices in pairs (plus possibly some closed circuits, which only add length). So every possible route repeats, at the least, a set of paths joining the odd vertices in pairs. The cheapest way to join a given pair is a shortest path, and checking every pairing finds the cheapest overall. The route can’t be shorter than the total of all edges plus this cheapest set of repeats, and the Eulerian circuit of the new graph achieves exactly that length, so it’s the shortest route.