Skip to content

Travelling salesperson

puzzles

Level 3 of 3

Also called The travelling salesman problem and Exhaustive search in Steinhaus-Johnson-Trotter order.

test yourself

Six questions, four to pick from and two for paper.

fresh numbers: the questions a run answers, asked again on new numbers

choose one

question 1

How many orders does the method try on this map of 5 places, from A?

436257ABCFG
the answer, and why

the answer is A

The start stays first, and the other 4 places go in every order. 4 times 3 times 2 times 1 is 24.

if you chose another

  • That is 5!5!, which moves the start too. The start never moves.
  • That is one order for each place.
  • That is half of 24, the different round trips. The method tries each trip both ways.

question 2

How many legs does the method add up on the same map?

436257ABCFG
the answer, and why

the answer is A

24 orders, each a round trip of 5 legs. 24 times 5 is 120, which is 5!5!.

if you chose another

  • That is the orders. Each order adds up 5 legs.
  • That is the legs of one round trip.
  • That is 5 legs in each of 5 orders, as if there were one order per place. There are 24.

question 3

On this ring from A, which order is the same round trip as A B F E?

4352ABEF
the answer, and why

the answer is D

A E F B passes the same places backwards, B, F and E, then home. Each leg is as long both ways.

this tests where the formula comes from, on the learn page

if you chose another

  • It has legs B-E and F-A; A B F E has B-F and E-A.
  • That passes A to F and B to E, legs A B F E never uses: 18, not 14.
  • A E F B is the same trip, the other way round.

question 4

One more place joins a map of 6 places in one piece. What happens to the legs?

the answer, and why

the answer is B

6 places take 6!6!, 720 legs. 7 places take 7!7!, which is 7 times 720, 5,040.

this tests where the formula comes from, on the learn page

if you chose another

  • That would be 1,440. The legs grow faster than doubling.
  • That would be 727. Each new place multiplies the work.
  • That would be 4,320. 7 is the new number of places.

pen and paper

question 5about 8 minutes

Try every order on the ring A-B 4, B-F 3, F-E 5, E-A 2, from A, by hand.

  1. List the 6 orders, each with its total.
  2. Which trip is kept?
  3. Why is A E F B not kept?
a hint

B to E is shortest through A, 6, and F to A is 7 either way round.

a worked answer

A B E F 22, A B F E 14 and A F B E 18. Then A F E B 22, A E F B 14 and A E B F 18. A B F E, 14, is kept. A E F B is the same trip backwards, 14 too, and only a shorter trip replaces the one kept.

this tests how it works, on the learn page

what a full answer includes
  • The six orders, with totals 22, 14, 18, 22, 14 and 18, in any order.
  • A B F E, 14.
  • It is A B F E backwards, 14 too, not shorter.

question 6about 6 minutes

A computer adds up a billion legs a second. How long does trying every order take on 20 places?

  1. How many legs is that?
  2. How many seconds?
  3. About how many years?
a hint

Use question 2 of the learn page and a calculator. A year is about 31,557,600 seconds.

a worked answer

20! is 2,432,902,008,176,640,000 legs. Divided by a billion, that is about 2,433,000,000 seconds. Divided by 31,557,600, about 77 years.

Question 2: how many legs, LL, does the method add up on a map of nn places in one piece?
  1. the move: legs in each order

    the line:
    L=n×(n−1)!L = n \times (n - 1)!

    why it is allowed: A round trip of nn places has nn legs, one from each stop to the next, the last back to the start. By question 1, the method tries (n−1)!(n - 1)! orders and adds up nn legs in each. For the ring, 4 legs in each of 6 orders.

  2. the move: one product

    the line:
    L=n!L = n!
    placeslegstimes the row above
    6720
    75,0407 times
    840,3208 times
    9362,8809 times
    12479,001,600
    Each new place multiplies the legs by the new number of places, faster than any doubling.

    why it is allowed: nn times (n−1)!(n - 1)! multiplies every whole number from nn down to 1, which is n!n!. For the ring, 4 times 6, which is 24.

  3. the move: a ceiling

    the line:
    L≤n!L \le n!

    why it is allowed: By line 2, LL is n!n!, so at most n!n!.

  4. the move: read the bound

    the line:
    L∈O(n!)L \in O(n!)

    why it is allowed: By line 3: at most 1 times n!n!, at every nn.

  5. the move: a floor

    the line:
    L≥n!L \ge n!

    why it is allowed: By line 2 again, LL is n!n!, so at least n!n!.

  6. the move: read the bound

    the line:
    L∈Ω(n!)L \in \Omega(n!)

    why it is allowed: By line 5: at least 1 times n!n!, at every nn.

  7. the move: both together

    the line:
    L∈Θ(n!)L \in \Theta(n!)

    why it is allowed: Lines 4 and 6 bound LL by the same growth, n!n!, from above and below.

try it with a small nn: at n=4n = 4, line 1 gives L=24L = 24, which you can work out by hand

this tests where the formula comes from, on the learn page

what a full answer includes
  • 2,432,902,008,176,640,000 legs.
  • About 2,433,000,000 seconds.
  • About 77 years.