The Nearest Neighbor (NN) heuristic is a simple and intuitive algorithm for solving the Traveling Salesman Problem (TSP). Starting from an arbitrary city, it repeatedly visits the nearest unvisited city until all cities are visited. While it is easy to implement and often produces acceptable solutions quickly, the NN heuristic can sometimes yield very poor solutions, especially depending on the starting city. Below are two examples that demonstrate cases where the NN heuristic performs poorly, resulting in a tour length close to or exceeding twice the optimal tour length.
Example 1: The "Lollipop" Graph
Description:
Imagine a set of cities arranged in a "lollipop" shape, consisting of a clique (fully connected subgraph) and a path connected to it.
-
Clique (Cluster of Cities): There are ( k ) cities densely packed together, with very small distances between them (effectively zero for this example). Think of these cities as being located at the same point or forming a small circle where the distances between them are negligible.
-
Path (Linear Chain of Cities): Connected to the clique is a path of ( n ) cities arranged in a straight line, with uniform distances ( d ) between successive cities.
Setup:
- Cities in the Clique: Cities ( C_1, C_2, \ldots, C_k ).
- Cities in the Path: Cities ( P_1, P_2, \ldots, P_n ).
- Connection: City ( C_1 ) in the clique is connected to city ( P_1 ) in the path.
- Distances:
- Between cities in the clique: ( \approx 0 ).
- Between successive cities in the path: ( d ) (e.g., ( d = 1 )).
Nearest Neighbor Tour:
Suppose we start at the end of the path, city ( P_n ). The NN heuristic proceeds as follows:
-
Traverse the Path Backward:
- From ( P_n ) to ( P_{n-1} ), ( P_{n-1} ) to ( P_{n-2} ), ..., until ( P_1 ).
- Total distance for the path: ( (n-1) \times d ).
-
Move to the Clique:
- From ( P_1 ) to ( C_1 ).
- Distance: negligible (assuming ( P_1 ) and ( C_1 ) are directly connected).
-
Traverse the Clique:
- Visit all cities in the clique ( C_1, C_2, \ldots, C_k ).
- Total distance: negligible.
-
Return to Starting City:
- From ( C_k ) back to ( P_n ).
- This requires traversing the entire path again, covering a distance of ( n \times d ).
Total NN Tour Length:
- Path traversal to the clique: ( (n-1) \times d ).
- Return path traversal: ( n \times d ).
- Total distance: ( (n-1)d + nd = (2n - 1)d ).
Optimal Tour:
An optimal tour would start at the clique, visit all cities in the clique first (negligible distance), proceed along the path from ( P_1 ) to ( P_n ) (distance ( (n - 1)d )), and then return directly from ( P_n ) back to the starting city in the clique (assuming a direct connection or small distance compared to the path length).
Total Optimal Tour Length:
- Path traversal: ( (n - 1)d ).
- Return to starting city: negligible.
- Total distance: ( (n - 1)d ).
Approximation Ratio:
- NN Tour Length / Optimal Tour Length ( = \frac{(2n - 1)d}{(n - 1)d} \approx 2 ), especially for large ( n ).
Conclusion:
In this example, the NN heuristic produces a tour that is almost twice as long as the optimal tour. The poor performance arises because the NN heuristic, starting from one end of the path, is forced to backtrack along the entire path to return to the starting city after visiting the clique. The optimal solution avoids this by starting at the clique and traversing the path in one direction only.
Example 2: Cities Placed in a "Double Star" Configuration
Description:
Consider two clusters of cities (stars) located a significant distance apart.
-
Cluster A: Contains ( m ) cities all located very close to each other at position ( (0, 0) ). Distances between these cities are negligible.
-
Cluster B: Contains ( m ) cities all located very close to each other at position ( (D, 0) ), where ( D ) is a large distance compared to the distances within clusters.
Setup:
- Cities in Cluster A: ( A_1, A_2, \ldots, A_m ).
- Cities in Cluster B: ( B_1, B_2, \ldots, B_m ).
- Distances:
- Between any two cities within the same cluster: negligible.
- Between any city in Cluster A and any city in Cluster B: ( D ).
Nearest Neighbor Tour Starting in Cluster A:
-
Traverse Cluster A:
- Start at city ( A_1 ) and visit all other cities ( A_2, \ldots, A_m ).
- Total distance: negligible.
-
Move to Cluster B:
- From the last city in Cluster A to the nearest city in Cluster B (any ( B_i )).
- Distance: ( D ).
-
Traverse Cluster B:
- Visit the remaining cities ( B_2, \ldots, B_m ).
- Total distance: negligible.
-
Return to Starting City:
- From the last city in Cluster B back to the starting city ( A_1 ).
- Distance: ( D ).
Total NN Tour Length:
- Distance between clusters: ( 2D ).
- Total distance: ( 2D ).
Optimal Tour:
An optimal tour would alternate visits between the clusters to minimize the number of times the large distance ( D ) is traversed. One possible optimal tour:
- Alternate Between Clusters:
- From ( A_1 ) to ( B_1 ) (distance ( D )).
- From ( B_1 ) to ( A_2 ) (distance ( D )).
- From ( A_2 ) to ( B_2 ) (distance ( D )).
- Continue this pattern until all cities are visited.
Total Optimal Tour Length:
- Number of crossings between clusters: ( 2m - 1 ) (starting from ( A_1 ) and ending at ( B_m )).
- Total distance: ( (2m - 1) \times D ).
However, since each crossing incurs a distance of ( D ), and we cannot avoid crossing between clusters, the optimal tour length depends on the specific arrangement and may not be shorter than the NN tour in terms of total ( D ) traversed. This example shows that sometimes the NN heuristic can be as good as the optimal tour when the main distances are dominated by unavoidable large distances.
Modified Setup for a Worse Approximation:
To demonstrate a worse-case scenario, we can adjust the distances within clusters and the distances between clusters.
- Within-Cluster Distances: Set to zero (cities are at the exact same point).
- Between-Cluster Distances: Slightly more complicated; suppose we adjust the positions so that the optimal tour can avoid some of the large distances by carefully choosing the order of visiting cities.
But generally, the approximation ratio may not exceed 2 in this configuration unless additional constraints or specific distance functions are applied.
Conclusion:
While this example doesn't achieve an approximation ratio significantly greater than 2, it illustrates that the NN heuristic can fail to find the optimal solution and can result in a tour length close to twice that of the optimal tour, especially when there are large distances between clusters of cities.
Explanation:
These examples demonstrate that the Nearest Neighbor heuristic can produce solutions that are significantly longer than the optimal tour, particularly when the city arrangement includes clusters with large inter-cluster distances or when starting from specific cities leads the heuristic to make suboptimal choices. The key factors contributing to the poor performance are:
-
Greedy Choice Pitfalls: The NN heuristic makes decisions based only on the immediate nearest city without considering future consequences, which can lead to long detours.
-
Dependency on Starting City: The choice of the starting city can dramatically affect the quality of the solution. Starting at different cities may result in better or worse tours due to the heuristic's nature.
-
Large Inter-City Distances: Significant differences in distances between cities (e.g., small intra-cluster distances versus large inter-cluster distances) can mislead the heuristic into incurring large total distances.
These examples underscore the importance of using more sophisticated algorithms or combining heuristics with other optimization techniques when solving the TSP, especially for instances where the NN heuristic is likely to perform poorly.