Union Find

union-find(V, E)
	let P = empty set
	for v in V:
		makeSet(v)
	for (u, v) in E:
		if find(u) != find(v)
			union(find(u), find(v))

Optimisation

Lemma: In a series of operations of makeSet, union and find on n elements using the size-heuristic, no element can have its cell field assigned more than logn+1 times.
Proof: Whenever the cell value of a node changes, its cardinality will at-least double (only way cells get merged is if its size is bigger than some other cell). But 1|vcell|n. This can happen no more than logn times.

find(v)
	if v -> parent is not a root:
		v -> parent = find(v -> parent)
	return v -> parent