implementation of the coursera solution to the union find problem. with tests.