The Travelling Salesperson Problem (AQA A-Level Further Maths): Revision Notes
The Travelling Salesperson Problem
Introduction to the problem
A salesperson must visit multiple locations and return to their starting point as efficiently as possible. This situation forms the basis of an important optimization problem in graph theory.
The travelling salesman problem is one of the most studied problems in computational mathematics and has practical applications in logistics, manufacturing, DNA sequencing, and circuit board design.
The travelling salesman problem asks you to find a route that visits every vertex of a network and returns to the starting vertex in the shortest possible total distance.
A Hamiltonian cycle (also called a Hamiltonian tour) is a closed path that visits every vertex of a network exactly once before returning to the start.
Classical TSP vs practical TSP
The classical travelling salesman problem requires you to visit every vertex of a network exactly once and return to the start in the minimum possible distance. In other words, you need to find a minimum weight Hamiltonian cycle.
However, real-world situations may not match this classical pattern. Two main issues can arise:
Common Issues with Practical TSP:
-
No Hamiltonian cycle exists: Some networks cannot be traversed by visiting each vertex exactly once. For instance, any complete tour of certain graphs would require visiting some vertices multiple times.
-
Triangle inequality not satisfied: The network may violate the triangle inequality, particularly when weights represent travel times. In such cases, the direct route between two vertices might not be the quickest path.
When facing a practical TSP that doesn't fit the classical model, you convert it to an equivalent classical problem first.
Converting practical TSP to classical TSP
To solve a practical TSP with vertices, follow these steps:
- Create a complete network containing the shortest distances between every pair of vertices
- Find a minimum weight Hamiltonian cycle for this complete network (this is now a classical problem)
- Interpret the solution in the context of the original practical situation
Worked Example 1: Converting to a Complete Network
Consider this network where a Hamiltonian cycle exists ( with total weight 36), but the best practical solution is actually with total weight 32.
Solution:
First, construct the complete network by finding shortest distances between all pairs of vertices. For example, the shortest distance from to is 13 (using route ) rather than the direct edge weight of 15.
The complete network shows all shortest paths. By inspection, the minimum Hamiltonian tour is .
To interpret this for the original network:
- Shortest distance
- Shortest distance
Therefore, the solution to the practical problem is .
Finding the optimal solution
The only certain way to find the best tour is to check every possible Hamiltonian cycle.
For a complete network with vertices, there are possible first arcs to travel, then second arcs, and so on. Since each tour can be listed twice (forwards and backwards), the formula becomes:
A network with vertices has possible tours.
This number grows exponentially. Even for relatively small networks, checking every cycle becomes computationally impossible. For example, a network with 10 vertices has possible tours.
Because of this exponential growth, you need methods to:
- Find a good (though not necessarily optimal) solution within reasonable time
- Determine whether your solution is sufficiently close to optimal
Heuristic algorithms
A heuristic algorithm finds a good solution that may not be perfect. For the TSP, a simple heuristic method is the nearest neighbour algorithm, which is an example of a greedy algorithm.
Heuristic algorithms trade optimality for speed. While they don't guarantee the best possible solution, they can find very good solutions quickly, making them practical for large-scale problems where finding the exact optimal solution would take too long.
The nearest neighbour algorithm
Step 1: Choose a starting vertex
Step 2: From your current position, choose the arc with minimum weight leading to an unvisited vertex. Travel to that vertex.
Step 3: If unvisited vertices remain, return to Step 2
Step 4: Travel back to
If multiple arcs have equal weight at Step 2, choose one at random. You can rerun the algorithm with different choices to see if they produce better solutions.
Important Strategy:
You should repeat the algorithm starting from each vertex in turn. This generates several different tours, from which you select the best.
Note: The 'starting vertex' in the algorithm refers to where you begin the process of finding a tour. Once you have identified a tour, you can start your actual journey at any vertex on that tour.
Worked Example 2: Nearest Neighbour Algorithm
This network shows distances (in km) between five towns. Use the nearest neighbour algorithm, starting from each vertex, to find a route for a travelling salesman based at who must visit every town.

Solution:
Starting from , the nearest vertex is (weight )
From , the nearest unvisited vertex is (weight )
From , the nearest unvisited vertex is (weight )
From , the nearest unvisited vertex is (weight )
No more unvisited vertices remain, so travel back to (weight )
The total weight for tour is
Repeating this process starting from each vertex:
| Start vertex | Tour(s) | Total weight |
|---|---|---|
| 55 | ||
| 59 | ||
| , | 58, 53 | |
| 59 | ||
| , | 58, 53 |
Note that and are the same tour (one is the reverse of the other).
For a salesman based at , the best tour found is km.
Worked Example 3: Practical Application
The diagram shows travel times (in minutes) between six locations.
a) Draw a table of shortest travel times.
b) Use the nearest neighbour algorithm to find a solution to the travelling salesman problem. List the route the salesperson will take.
c) Show by inspection that the solution found in b is not optimal.
Solution:
a) The minimum travel times between all pairs of vertices are:
| - | 7 | 10 | 15 | 12 | 5 | |
| 7 | - | 3 | 8 | 5 | 6 | |
| 10 | 3 | - | 5 | 2 | 9 | |
| 15 | 8 | 5 | - | 4 | 11 | |
| 12 | 5 | 2 | 4 | - | 7 | |
| 5 | 6 | 9 | 11 | 7 | - |
b) Starting from , the nearest vertex is ()
From , the nearest unvisited vertex is ()
From , the nearest unvisited vertex is ()
From , the nearest unvisited vertex is ()
From , the nearest unvisited vertex is ()
All vertices visited, so return to ()
The route is , with total weight minutes.
Repeating from other starting vertices:
| Start vertex | Tour(s) | Total weight |
|---|---|---|
| 35 | ||
| 32 | ||
| 35 | ||
| 35 | ||
| 35 | ||
| 32 |
The two 32-minute tours are identical. With as the starting vertex, these give .
The salesperson travels , because the shortest route from to goes through .
c) On the original network, the tour minutes, so the solution found in b is not optimal.
Finding upper bounds
Since no efficient algorithm guarantees finding the optimal solution length , you need a way to assess whether a solution is good enough. You do this by finding two values called an upper bound and a lower bound, such that:
lower bound upper bound
The closer these two bounds are to each other, the more accurately you know the length of the optimal tour. You should try to find the smallest possible upper bound and the largest possible lower bound.
If you have found a tour, it is either optimal or longer than optimal. This means:
The length of any known tour is an upper bound.
Using the nearest neighbour algorithm automatically provides an upper bound (though not necessarily a good one).
Upper bound using minimum spanning tree
An alternative method uses a minimum spanning tree for the network. You could visit every vertex by travelling once in each direction along every arc of the minimum spanning tree. Therefore:
is an upper bound.
This is usually not a good upper bound, but you can improve it using short cuts.
Worked Example 4: MST and Short Cuts for Upper Bound
Use the minimum spanning tree (MST) and short cuts to find an upper bound for the optimal solution of the TSP for this network.

Solution:
Using Kruskal's or Prim's algorithm to find two MSTs, each with total length 17:
First MST gives an upper bound of
For the first MST, this upper bound is equivalent to the route .
To improve this, replace (total weight ) with the direct route (weight 10).
This reduces the bound by .
The improved upper bound is .
However, this route is now a Hamiltonian tour, so there are no more short cuts possible.
For the second MST, the initial upper bound of 34 is equivalent to the route .
To improve this, replace (total weight ) with (weight 10).
This reduces the bound by .
The improved upper bound is .
This route is also a Hamiltonian tour with no further short cuts possible.
Of the two values found, the best upper bound is 18.
Remember: You always want the upper bound to be as small as possible.
Finding lower bounds
In addition to an upper bound, you need to find a lower bound.
Suppose you have a network as shown. The optimal tour enters and leaves vertex along two of the arcs , , , and .

You separate these arcs from the rest of the network. The two arcs involved in the tour must have a combined weight of at least (the sum of the two smallest weights from ).
The remaining three arcs of the tour connect vertices , , , and , forming a spanning tree for that subgraph.
The minimum spanning tree for this subgraph has weight , so the three arcs in the tour must have a total weight of at least 19.
Therefore, the complete tour has a total weight of at least .
This provides a lower bound for the tour.
To obtain the best possible lower bound, you could repeat this process by removing each vertex in turn. Removing different vertices gives different lower bounds. You want the lower bound to be as large as possible, so select the largest value obtained.
Algorithm for finding a lower bound
Step 1: Choose a vertex
Step 2: Identify the two lowest weights, and , of the arcs connected to
Step 3: Remove and its connecting arcs from the network. Find the total weight, , of the minimum spanning tree of the remaining subgraph.
Step 4: Calculate lower bound
Step 5: If possible, choose another vertex and return to Step 2
Choose the largest result obtained as the best lower bound.
Worked Example 5: Finding Lower Bounds
For the network shown:
| - | 12 | 6 | 7 | 2 | |
| 12 | - | 9 | 7 | 10 | |
| 6 | 9 | - | 4 | 8 | |
| 7 | 7 | 4 | - | 5 | |
| 2 | 10 | 8 | 5 | - |
a) Find a lower bound for the optimal tour by deleting vertex
b) Find a second lower bound by deleting vertex
c) State which value is the better lower bound
d) Given an upper bound of 32, write an inequality for , the optimal tour
Solution:
a) The shortest arcs from are and

The minimum spanning tree is , , and .
Using Prim's algorithm: lower bound
b) The shortest arcs from are and
The minimum spanning tree of the remaining vertices is , , and .
Lower bound
c) Since , the better lower bound is 27
d) The optimal tour length lies between the lower and upper bounds, so
Note: The arcs forming the better lower bound (, , , , and ) do not form a tour themselves. If they did form a tour, you would know that exactly.
Key Point About Lower Bounds:
If you find a lower bound which forms a tour, then that tour is the optimal solution. If none of the possible lower bounds form a tour, the optimal tour must be greater than the best lower bound.
Summary
Key Points to Remember:
-
The travelling salesman problem asks for the shortest route that visits every vertex and returns to the start. The classical version requires visiting each vertex exactly once.
-
Convert a practical TSP to a classical TSP by creating a complete network of shortest distances, then finding a minimum weight Hamiltonian cycle.
-
There are possible tours in a network with vertices, making exhaustive checking impractical for large networks.
-
The nearest neighbour algorithm is a heuristic method that builds a tour by repeatedly choosing the shortest available arc to an unvisited vertex. Run it from each vertex and select the best result.
-
Upper bounds can be found from any known tour, or by using and applying short cuts to improve it. You want the smallest possible upper bound.
-
Lower bounds are found by deleting a vertex, taking the sum of its two smallest arcs, and adding the MST of the remaining vertices. Repeat for each vertex and choose the largest result.
-
The optimal tour length satisfies: lower bound upper bound. If a lower bound forms a tour, it is the optimal solution.