Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Nearest neighbour algorithm
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Algorithm for the travelling salesman problem}} {{About|an approximation algorithm to solve the [[travelling salesman problem]]||Nearest neighbor (disambiguation){{!}}Nearest neighbor}} {{Infobox Algorithm |class=[[Approximation algorithm]] |image= |caption= |data=[[Graph (data structure)|Graph]] |time=<math>\Theta(N^2)</math> |space=<math>\Theta(N)</math> |optimal=No |complete= }} The '''nearest neighbour algorithm''' was one of the first [[algorithm]]s used to solve the [[travelling salesman problem]] approximately. In that problem, the salesman starts at a random city and repeatedly visits the nearest city until all have been visited. The algorithm quickly yields a short tour, but usually not the optimal one. ==Algorithm == These are the steps of the algorithm: # Initialize all vertices as unvisited. # Select an arbitrary vertex, set it as the current vertex '''u'''. Mark '''u''' as visited. # Find out the shortest edge connecting the current vertex '''u''' and an unvisited vertex '''v'''. # Set '''v''' as the current vertex '''u'''. Mark '''v''' as visited. # If all the vertices in the domain are visited, then terminate. Else, go to step 3. The sequence of the visited vertices is the output of the algorithm. The nearest neighbour algorithm is easy to implement and executes quickly, but it can sometimes miss shorter routes which are easily noticed with human insight, due to its "greedy" nature. As a general guide, if the last few stages of the tour are comparable in length to the first stages, then the tour is reasonable; if they are much greater, then it is likely that much better tours exist. Another check is to use an algorithm such as the [[Upper and lower bounds|lower bound]] algorithm to estimate if this tour is good enough. In the worst case, the algorithm results in a tour that is much longer than the optimal tour. To be precise, for every constant '''r''' there is an instance of the traveling salesman problem such that the length of the tour computed by the nearest neighbour algorithm is greater than '''r''' times the length of the optimal tour. Moreover, for each number of cities there is an assignment of distances between the cities for which the nearest neighbour heuristic produces the unique worst possible tour. (If the algorithm is applied on every vertex as the starting vertex, the best path found will be better than at least N/2-1 other tours, where N is the number of vertices.)<ref>G. Gutin, A. Yeo and A. Zverovich, 2002</ref> The nearest neighbour algorithm may not find a feasible tour at all, even when one exists. ==Notes== <references /> ==References== * G. Gutin, A. Yeo and A. Zverovitch, Exponential Neighborhoods and Domination Analysis for the TSP, in The Traveling Salesman Problem and Its Variations, G. Gutin and A.P. Punnen (eds.), Kluwer (2002) and Springer (2007). * G. Gutin, A. Yeo and A. Zverovich, [http://www.sciencedirect.com/science/article/pii/S0166218X01001950 Traveling salesman should not be greedy: domination analysis of greedy-type heuristics for the TSP]. Discrete Applied Mathematics 117 (2002), 81β86. * J. Bang-Jensen, G. Gutin and A. Yeo, [http://www.sciencedirect.com/science/article/pii/S1572528604000222 When the greedy algorithm fails]. Discrete Optimization 1 (2004), 121β127. * G. Bendall and F. Margot, [http://www.sciencedirect.com/science/article/pii/S1572528606000430 Greedy Type Resistance of Combinatorial Problems], Discrete Optimization 3 (2006), 288β298. {{DEFAULTSORT:Nearest Neighbour Algorithm}} [[Category:Travelling salesman problem]] [[Category:Approximation algorithms]] [[Category:Heuristic algorithms]] [[Category:Graph algorithms]]
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:About
(
edit
)
Template:Infobox Algorithm
(
edit
)
Template:Short description
(
edit
)
Search
Search
Editing
Nearest neighbour algorithm
Add topic