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 initself nr:
self.id nr
self.ptr self
self.length
def strself:
return fselfidselflengthselfptrid
def lookupself:
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 joinself 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
The unit test is as follows:
def showeles:
for ele in eles:
printele
print
eles Elementi for i in range
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
elesjoineles
showeles
and should give you the following output:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
