Jump to content

Nearest neighbour algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 80.128.181.114 (talk) at 06:39, 26 February 2002. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The nearest neighbour algorithm was one of the first algorithms used to determine a solution to the travelling salesman problem, and usually comes to within twenty percent of the optimal route. It is, however, a lot faster than testing every route.

These are the steps of the algorithm:

1. Make two sets of nodes, set A and set B, and put all nodes into set B

2. Put your starting node into set A

3. Pick the node which is closest to the last node and is not in set A; put this node into set A

4. Repeat step 3 until all nodes are in set A