Disjoint Set

Download

Download jar file or use maven. psjava requires Java 1.6 (or above)

<dependency>
    <groupId>org.psjava</groupId>
    <artifactId>psjava</artifactId>
    <version>0.1.19</version>
</dependency>

Example Code

DisjointSet<String> set = GoodDisjointSet.create();

set.makeSet("A");
set.makeSet("B");
set.makeSet("C");
set.makeSet("D");

set.union("C", "D");

// representiatives for "C", "D" are now same.

String rep1 = set.find("C");
String rep2 = set.find("D");

Implementation


Copyright 2014 psjava team. View on GitHub