Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the Minimum Spanning Tree of a graph 2

Status
Not open for further replies.

saintofkillers

Technical User
Jun 11, 2004
1
AU
Hi, i'm having trouble trying to code in java a method:

public TSPGraph mst() {
// these are my attributes
/* problemSize is the size of the graph, i.e. 14 vertcies.*/
int [] in = new int [problemSize];
int [] out = new int [problemSize];
int [] d = new int [problemSize];
int k = problemSize;
int vertex = 1;
TSPGraph mspt = new TSPGraph (k);

for finding the minimum spanning tree for a weighted TSPGraph, that will be returned as another TSPGraph object.

I've used a variety of nested for loops and if statements for a week to no avail trying to check every vertex for all the paths that are connected to it and then determining
if the weight of that path is less than the other paths etc...

Is there anyone that can show me the code to perform and find the minimum spanning tree of a graph so i then can perform a preorder traversal of it.

Thankyou very kindly for your time.
 
take a look at Kruskals algorithm or Prims algorithm they should both compute a minimum spanning tree for you, although i dont have any code as i have never implemented any of them. Im sure a google search would turn something up
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top