Exemplo n.º 1
0
 public Graph( int V, int E)
 {
     DisJointSets = new Subset[V];
     for(int i = 0; i < V; i++)
     {
         DisJointSets[i] = new Subset(i);
     }
     Edges = new Edge[E];
     for (int i = 0; i < E; i++)
     {
         Edges[i] = new Edge();
     }
     GraphVertices = V;
     GraphEdges = E;
 }
Exemplo n.º 2
0
 public int FindPathByCompression(Subset[] subsets,int x)
 {
     if(subsets[x].Parent != x)
     {
         //promote the deep child as the direct child of parent's parent
         subsets[x].Parent = FindPathByCompression(subsets, subsets[x].Parent);
     }
     return subsets[0].Parent;
 }