I want to write a java program that solves the traveling salesman problem with the nearest neighbor heuristic. The steps of the algorithm would be something like this:
Step 1: Start with any random vertex, call it current vertex
Step 2: Find an edge which gives minimum distance between the current vertex and an unvisited vertex, call it V
Step 3: Now set that current vertex to unvisited vertex V and mark that vertex V as visited
Step 4:Terminate the condition, if all the vertices are visited atleast once
Step 5: Go to step 2
I have problems to figure out which data structures would be suitable to solve this problem. How can I identify the node with the smallest distance to the current node (step 2)? Would a priority queue be a good choice? What other data structures could I use? How can I make sure, that the second last node in the tour connects to the start node? Should I use a stack? What else could I use?