QuickUnion algorithms implementation