0

I'm trying to traverse through an MST. I want to be able to start and finish from one vertex and visit every vertex (TSP). I don't care about efficiency, I just want to be able to visit every vertex in the MST and come back to the source vertex. Any suggestions? I've tried implementing the MST with

ArrayList<ArrayList<Vertex>> mst = new ArrayList<ArrayList<Vertex>>();

but I don't know how to start doing the DFS.

kennysong
  • 504
  • 2
  • 6
  • 23
  • Does this answer help you? http://stackoverflow.com/questions/27650579/find-minimum-spanning-tree-using-depth-first-search-in-c – Christian Apr 18 '17 at 04:56

1 Answers1

0

Don't do a depth first traversal of a Minimum Spanning Tree, do a preorder traversal. In a preorder traversal, the root of the tree is the first node traversed, so after the preorder traversal of the MST add the root to the nodes traversed. This will give you all of the nodes in the tree starting and ending with the root. This will let you start and end on the root of the MST.