From 57227c0cf9a6535401dab5b333cc3ed1d97bea38 Mon Sep 17 00:00:00 2001 From: nandubhai Date: Mon, 30 Oct 2017 23:32:08 +0530 Subject: [PATCH] Disjoint Set Disjoint Set union --- DisjointSet.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 DisjointSet.java 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