Question: Consider the following updated pseudocode for findSet with path compression. parent [ n ] / / A array of size n such that parent [

Consider the following updated pseudocode for findSet with path compression.
parent[n]// A array of size n such that parent[i]=i
findSet(u):
if(parent[u]== u):
return u
parent[u]= findSet(parent[u])
return parent[u]
unionSet(u, v):
x = findSet(u)
y = findSet(v)
if(x != y):
parent[y]= x
You are given an array parent =[0,1,2,3,4,5] representing the initial parent array of a Disjoint Set Union (DSU) data structure for 6 vertices labelled from 0 to 5. After performing the following operations in given order:
unionSet(0,3)
unionSet(1,3)
unionSet(2,5)
unionSet(1,4)
What will be the resulting parent array using the provided pseudocode?
1.[1,1,2,0,1,2]
2.[1,1,1,0,2,2]
3.[1,1,2,1,2,2]
4.[1,1,1,2,1,2]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!