7 elements, each its own set: parent[i] = i marks a root, and every size is 1. The parent row is the whole structure. Following parents from any element leads to the root that names its set.
7 singleton sets.
find(0): parent[0] = 0, so 0 is a root already. Its set is 0.
find 0 reaches root 0 after 0 steps.
find(1): parent[1] = 1, so 1 is a root already. Its set is 1.
find 1 reaches root 1 after 0 steps.
Roots 0 (size 1) and 1 (size 1). Union by size hangs the smaller root under the larger: parent[1] = 0, and 0's size grows to 2. Sets left: 6.
Root 1 now points at 0. 6 sets remain.
find(2): parent[2] = 2, so 2 is a root already. Its set is 2.
find 2 reaches root 2 after 0 steps.
find(3): parent[3] = 3, so 3 is a root already. Its set is 3.
find 3 reaches root 3 after 0 steps.
Roots 2 (size 1) and 3 (size 1). Union by size hangs the smaller root under the larger: parent[3] = 2, and 2's size grows to 2. Sets left: 5.
Root 3 now points at 2. 5 sets remain.
find(4): parent[4] = 4, so 4 is a root already. Its set is 4.
find 4 reaches root 4 after 0 steps.
find(5): parent[5] = 5, so 5 is a root already. Its set is 5.
find 5 reaches root 5 after 0 steps.
Roots 4 (size 1) and 5 (size 1). Union by size hangs the smaller root under the larger: parent[5] = 4, and 4's size grows to 2. Sets left: 4.
Root 5 now points at 4. 4 sets remain.
find(1): climb the parents, 1 > 0. The climb ends at 0, whose parent is itself, so 0 names the set.
find 1 reaches root 0 after 1 steps.
find(3): climb the parents, 3 > 2. The climb ends at 2, whose parent is itself, so 2 names the set.
find 3 reaches root 2 after 1 steps.
Roots 0 (size 2) and 2 (size 2). Union by size hangs the smaller root under the larger: parent[2] = 0, and 0's size grows to 4. Sets left: 3.
Root 2 now points at 0. 3 sets remain.
find(5): climb the parents, 5 > 4. The climb ends at 4, whose parent is itself, so 4 names the set.
find 5 reaches root 4 after 1 steps.
find(3): climb the parents, 3 > 2 > 0. The climb ends at 0, whose parent is itself, so 0 names the set.
find 3 reaches root 0 after 2 steps.
Path compression: every element on that path now points straight at 0. The next find on any of them is one step. The sets did not change, only their shape.
Path compressed: 3, 2 now point at 0.
Roots 0 (size 4) and 4 (size 2). Union by size hangs the smaller root under the larger: parent[4] = 0, and 0's size grows to 6. Sets left: 2.
Root 4 now points at 0. 2 sets remain.
find(4): climb the parents, 4 > 0. The climb ends at 0, whose parent is itself, so 0 names the set.
find 4 reaches root 0 after 1 steps.
find(4) returns 0.
Result 0.
find(4): climb the parents, 4 > 0. The climb ends at 0, whose parent is itself, so 0 names the set.
find 4 reaches root 0 after 1 steps.
find(4) returns 0.
Result 0.
2 sets remain and the longest path to a root is 2. Union by size keeps depth at most log n, and path compression keeps flattening, so a sequence of m operations costs about O(m alpha(n)), effectively linear.
2 sets, longest path 2.