To union nodes and :
Find the leader of . Call it rootA.
Find the leader of . Call it rootB.
If rootA == rootB, they are already in the same group. Done.
Otherwise, set parent[rootA] = rootB (or vice versa).
Now everyone in 's old group points (eventually) to 's leader. The two groups are merged. This takes for the two find calls plus for the pointer update.
Space complexity is for the data structures used.