Question: Implement the disjoint set data structure. You can choose any programming language that the grader can understand, but you might have to change the mandatory

Implement the disjoint set data structure. You can choose any programming language that the grader can understand, but you might have to change the mandatory unit test and adapt the following layout.
```
class Element:
def __init__(self, nr):
self.id = nr
self.ptr = self
self.length =1
def __str__(self):
return f'{self.id}({self.length})->{self.ptr.id}'
def lookup(self):
"""returns the leader of the set self is in. The set is
compacted, meaning that all nodes on the path to the
leader now point directly to the leader."""
def join(self, other):
""" joins the leader of the smaller set with the leader of the
larger set.
The length of the leader of the smaller set is 0."""
```
The unit test is as follows:
```
def show(eles):
for ele in eles:
print(ele)
print()
eles =[Element(i) for i in range(20)]
eles[0].join(eles[1])
eles[2].join(eles[3])
eles[0].join(eles[2])
eles[5].join(eles[6])
eles[7].join(eles[6])
eles[3].join(eles[7])
eles[4].join(eles[2])
eles[8].join(eles[9])
eles[9].join(eles[6])
eles[10].join(eles[11])
eles[10].join(eles[12])
eles[14].join(eles[12])
eles[13].join(eles[10])
eles[15].join(eles[14])
eles[16].join(eles[15])
eles[17].join(eles[18])
```
eles[19].join(eles[18])
eles[17].join(eles[14])
show(eles)
and should give you the following output:
Implement the disjoint set data structure. You

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!