Showing posts with label Kruskal’s algorithm. Show all posts
Showing posts with label Kruskal’s algorithm. Show all posts

Thursday, April 14, 2011

Kruskal’s algorithm


import java.io.*;
  import java.util.*;
  class Graph
  {
  int i,n; //no of nodes
  int noe; //no edges in the graph
  int graph_edge[][]=new int[100][4];d
  int tree[][]=new int [10][10];
  int sets[][]=new int[100][10];
  int top[]=new int[100];
  int cost=0;
  void read_graph()
  {
                System.out.print("Enter the no. of nodes in the undirected weighted graph ::");
                n=getNumber();
                noe=0;
                System.out.println("Enter the weights for the following edges ::\n");
                for(int i=1;i<=n;i++)
                {
                                for(int j=i+1;j<=n;j++)
                                {
                                                System.out.print(" < "+i+" , "+j+" > ::");
                                                int w;
                                                w=getNumber();
                                                if(w!=0)
                                                {