Nearest Neighbour & Deleted Vertex Algorithms (DP IB Applications & Interpretation (AI)): Revision Note
Did this video help you?
Table of least distances
What is the practical travelling salesman problem?
The practical travelling salesman problem deals with graphs which might not satisfy either condition of the classical problem
The graph might not be complete
The direct route between any pair of vertices might not be the shortest route
Here are some real-life examples
Each train station in a rail network is not connected directly to every other station
It might be cheaper to translate a book from Mandarin to English and then to French than translating directing from Mandarin to French
You can convert a practical travelling salesman problem into a classical travelling salesman problem using a table of least distances
The table of least distances shows the shortest distance between any two vertices in a graph
The practical travelling salesman problem might not have a route that visits each vertex exactly once
Instead you need to find a minimum route that visits each vertex at least once
How can I find the table of least distances?
STEP 1
Fill in the information for vertices that are adjacent in the graphCheck if the direct route is the shortest route
If it is not, then find the length of the short route between them
STEP 2
Find the shortest route that can be travelled between each pair of vertices that are not adjacentThis completes the table
Examiner Tips and Tricks
Remember that the table of least values has a line of symmetry along the leading diagonal for an undirected graph, so complete one half carefully first, then map over to the second half.
In your exam, it is likely that one of the edges between a pair of vertices will not be the shortest route. Keep an eye out for this.
Worked Example
The graph G below contains six vertices representing villages and the roads that connect them. The weighting of the edges represents the time, in minutes, that it takes to walk along a particular road between two villages.

a) Explain why G is not complete graph.

b) Complete the table of least weights below.
| A | B | C | D | E | F |
---|---|---|---|---|---|---|
A |
|
|
|
|
|
|
B |
|
|
|
|
|
|
C |
|
|
|
|
|
|
D |
|
|
|
|
|
|
E |
|
|
|
|
|
|
F |
|
|
|
|
|
|


Nearest neighbour algorithm
What is the nearest neighbour algorithm?
The nearest neighbour algorithm can be used to find an upper bound for the minimum weight Hamiltonian cycle
This gives an upper bound to the travelling salesman problem
The nearest neighbour algorithm can only be used on a graph that is complete and satisfies the triangle inequality
The table of least distances must be found first if needed
How can I use the nearest neighbour algorithm to find an upper bound?
STEP 1
Choose a starting vertexThe upper bound depends on the starting vertex
Different vertices lead to different upper bounds
The best upper bound is the lowest
STEP 2
Follow the edge of least weight from the current vertex to an adjacent unvisited vertexIf there is more than one edge of least weight then pick any
You can circle the least value
STEP 3
Repeat step 2 until all vertices have been visitedThere should be exactly one circled value in each row and each column
STEP 4
Add the final edge to return to the starting vertex
Examiner Tips and Tricks
If asked to write down the route for the lower bound, don’t forget that some of the entries in the table of lowest distances may not be direct routes between vertices!
Worked Example
The table below contains six vertices representing villages and the roads that connect them. The weighting of the edges represents the time in minutes that it takes to walk along a particular road between two villages.
| A | B | C | D | E | F |
---|---|---|---|---|---|---|
A | - | 14 | 7 | 11 | 13 | 21 |
B | 14 | - | 13 | 18 | 13 | 9 |
C | 7 | 13 | - | 5 | 6 | 14 |
D | 11 | 18 | 5 | - | 10 | 18 |
E | 13 | 13 | 6 | 10 | - | 8 |
F | 21 | 9 | 14 | 18 | 8 | - |
Starting at village A, use the nearest neighbour algorithm to find the upper bound of the time it would take to visit each village and return to village A.


Deleted vertex algorithm
What is the deleted vertex algorithm?
The deleted vertex algorithm can be used to find a lower bound for the minimum weight Hamiltonian cycle
This gives a lower bound to the travelling salesman problem
The deleted vertex algorithm can only be used on a graph that is complete and satisfies the triangle inequality
The table of least distances must be found first if needed
Any Hamiltonian cycle whose length is equal to the lower bound solves the travelling salesman problem
Examiner Tips and Tricks
If you can find a lower bound that is equal to an upper bound, then this is the length of any solution to the travelling salesman problem.
How can I use the deleted vertex algorithm to find a lower bound?
STEP 1
Choose a vertex and delete it along with all edges that are directly connected to itThe lower bound depends on the deleted vertex
Deleting different vertices leads to different upper bounds
The best lower bound is the highest
STEP 2
Find a minimum spanning tree for the remaining graphYou can use Kruskal's algorithm or Prim's algorithm
STEP 3
Add the lengths of the two shortest edges that were deleted from the original graph to the weight of the minimum spanning tree
Examiner Tips and Tricks
Be careful when using a weighted adjacency table not to get confused between using Prim’s algorithm and the nearest neighbour algorithm.
Remember that Prim’s is used to find a minimum spanning tree, so vertices can be connected to several other vertices and hence can have more than one value in a column circled
When using the table for the nearest neighbour algorithm, vertices cannot be revisited so only one value will be circled in each column
Worked Example
The table below contains six vertices representing villages and the roads that connect them. The weighting of the edges represents the time in minutes that it takes to walk along a particular road between two villages.
| A | B | C | D | E | F |
---|---|---|---|---|---|---|
A | - | 14 | 7 | 11 | 13 | 21 |
B | 14 | - | 13 | 18 | 13 | 9 |
C | 7 | 13 | - | 5 | 6 | 14 |
D | 11 | 18 | 5 | - | 10 | 8 |
E | 13 | 13 | 6 | 10 | - | 8 |
F | 21 | 9 | 14 | 18 | 8 | - |
a) By deleting vertex A and using Prim’s algorithm, find a lower bound for the time taken to start at village A, visit each of the other villages and return to village A

b) Show that by deleting vertex B instead, a higher lower bound can be found.

Unlock more, it's free!
Did this page help you?