javaalgorithmdata-structuresnearest-neighborgreedy

What are the differences between Nearest Neighbor Algorithm and Greedy Algorithm?


I'm trying to develop 2 different algorithms for Travelling Salesman Algorithm (TSP) which are Nearest Neighbor and Greedy. I can't figure out the differences between them while thinking about cities.

I think they will follow the same way because shortest path between two cities is greedy and the nearest at the same time. which part am i wrong? Can you explain with a few cities example thank you!


Solution

  • Answer is NN Algorithm basically creates segments to closest nodes that it can reach, Greedy is the method of it but it directly takes the node which is the closest to current node.