Kruskal's algorithm is a greedy algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component).
import java.io.*;
class Tnode
{
char label;
//boolean vis;
int prev;
public Tnode(char lab)
{
label = lab;
//vis=false;
prev=-1;
}
}
Example run
import java.io.*;
class Tnode
{
char label;
//boolean vis;
int prev;
public Tnode(char lab)
{
label = lab;
//vis=false;
prev=-1;
}
}