union find algorithm

Here are some good resources to learn union find set:

https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf

http://www.geeksforgeeks.org/union-find-algorithm-set-2-union-by-rank/