Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement a disjoint set system using a tree representation (use references, or a parent array). In particular, you should implement an Initialize() function that creates
Implement a disjoint set system using a tree representation (use references, or a parent array). In particular, you should implement an Initialize() function that creates n one-element sets given an array of n things, as well as the functions Find() and Merge(). Implement the better version of disjoint sets (where smaller sets parent to larger sets and finds implement path compression).
Importing set.py should provide the following functions: set.Initialize(Values) -- return a new set system with one element per set. Values is a list of values for the sets set.Find(set, value) -- Return the name of the set in which value lives. Do path compression. Exactly what you return isn't important, as long as Find(set, val1) and Find(set, val2) are equal if and only if val1 and val2 are in the same set. set.Merge(set, value1, value2) -- Merge operation. Make sure you parent
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started