import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.Math; class Heaps { static Edge[] graph; static int[] noofedges; static int totalvertices,totaledges; static int MAXWT=999999; public Heaps() { } static public void createGraphM(int v, int e) { int i,j,k; graph=new Edge[v]; totalvertices=v; totaledges=e; for(i=0;i=v-1) { i--; } else noofedges[rv]++; } for(i=0;i0) { targetv[vcount++]=j; System.out.println(" " + j); } else { targetv[vcount++]=-1; } } Edge p = graph[i]; while(p!=null) { if(p.vertex>i) targetv[p.vertex-i-1]=-1; p=p.next; } int noe=noofedges[i]; System.out.println("Now adding " + noe +" edges for" + i); System.out.flush(); //____Now connect these vertices___ for(j=0;j=0 && targetv[cv]==-1) { cv--; } } if(cv>=0 && targetv[cv]!=-1) { targetv[cv]=-1; int wt=r.nextInt(MAXWT); connect(i,targetv[cv],wt); noofedges[i]--; noofedges[targetv[cv]]--; } else { System.out.println("Out of vertices"); System.out.flush(); } } } } } static private void connect(int v1,int v2, int wt) { if(v1==v2) return; Edge e1=new Edge(v2,wt); e1.next=graph[v1]; graph[v1]=e1; e1=new Edge(v1,wt); e1.next=graph[v2]; graph[v2]=e1; // System.out.println("Connecting : " + v1+","+v2); // System.out.flush(); } //1 for binary , 2 for fibonacci static private long prims(int heaptype,boolean comments) { int i; long starttime=1 , endtime=0; if(heaptype==2) { starttime=new Date().getTime(); Object[] llist=new FBNode[totalvertices]; FibonacciHeap bh=new FibonacciHeap(); int parentv[]=new int[totalvertices]; boolean inheap[]=new boolean[totalvertices]; int root=0; int extracted=0; Node n; //___Insert infinity for(i=0;i=3) { v=Integer.parseInt(args[0]); e=Integer.parseInt(args[1]); comments=Integer.parseInt(args[2]); } /* int maxi=30; int[] list=new int[maxi]; Object[] llist=new FBNode[maxi]; int i; Random r=new Random(); for(i=0;i0) comm=true; //if(comm) displaygraph(); long t; System.out.println("\nRunning Prim's Algorithm using Binary Heap"); t=prims(1,comm); System.out.println("t/(n.n.log(n)) : " + (double)(t)/(v*v*Math.log(v))); try{ new Thread().sleep(5000); } catch(Exception exc) {} System.out.println("\nRunning Prim's Algorithm using Fibonacci Heap"); t=prims(2,comm); System.out.println("t/(n.n) : " + (double)(t)/(v*v)); System.out.println("t/(n.log(n)) : " + (double)(t)/(v*Math.log((double)v))); } }