diff --git a/DisjointSet.java b/DisjointSet.java new file mode 100644 index 0000000..703c433 --- /dev/null +++ b/DisjointSet.java @@ -0,0 +1,98 @@ +// Java Program for union-find algorithm to detect cycle in a graph +import java.util.*; +import java.lang.*; +import java.io.*; + +class Graph +{ + int V, E; // V-> no. of vertices & E->no.of edges + Edge edge[]; // /collection of all edges + + class Edge + { + int src, dest; + }; + + // Creates a graph with V vertices and E edges + Graph(int v,int e) + { + V = v; + E = e; + edge = new Edge[E]; + for (int i=0; i