Nearest Neighbour & Deleted Vertex Algorithms (DP IB Applications & Interpretation (AI)): Revision Note

Naomi C

Written by: Naomi C

Reviewed by: Dan Finlay

Updated on

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 graph

    • Check 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 adjacent

    • This 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.

3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-1

a) Explain why G is not complete graph.

3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-1a-solution

b) Complete the table of least weights below.

 

A

B

C

D

E

F

A

 

 

 

 

 

 

B

 

 

 

 

 

 

C

 

 

 

 

 

 

D

 

 

 

 

 

 

E

 

 

 

 

 

 

F

 

 

 

 

 

 

3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-1bi-solution
3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-1bii-solution

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 vertex

    • The 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 vertex

    • If 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 visited

    • There 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.

yTG4~P0v_3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-2i-solution
3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-2ii-solution

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 it

    • The 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 graph

  • 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

3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-3a-solution

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

3-10-6-ib-ai-hl-bounds-for-travelling-salesman-problem-we-3b-solution

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Naomi C

Author: Naomi C

Expertise: Maths Content Creator

Naomi graduated from Durham University in 2007 with a Masters degree in Civil Engineering. She has taught Mathematics in the UK, Malaysia and Switzerland covering GCSE, IGCSE, A-Level and IB. She particularly enjoys applying Mathematics to real life and endeavours to bring creativity to the content she creates.

Dan Finlay

Reviewer: Dan Finlay

Expertise: Maths Subject Lead

Dan graduated from the University of Oxford with a First class degree in mathematics. As well as teaching maths for over 8 years, Dan has marked a range of exams for Edexcel, tutored students and taught A Level Accounting. Dan has a keen interest in statistics and probability and their real-life applications.