title: Implementing Disjoint Set System In Python
body: <p>What I have so far is largely based off page 571 of "Introduction To Algorithms" by Cormen et al.</p>
  
  <p>I have a Node class in python that represents a set:</p>
  
  <pre><code>class Node:
      def __init__(self, parent, rank = 0):
          self.parent = parent
          self.rank = rank</code></pre>
  
  <p>This implementation is going to use a <code>List</code> of Nodes as the forest (I am open to better ways to store the sets).</p>
  
  <p><code>Initialize()</code> returns a list of Nodes, that I will store in variable <code>set</code> and pass into the other functions.</p>
  
  <p><code>Find</code> searches through the forest for the value and returns the set that it appears in. I chose to use <code>for s in range(len(set)):</code> so that in the recursion I could shrink the list of sets being passed in by <code>set[s:]</code>.
  <pre><code>def Find(set, value):
      for s in range(len(set)):
          if value != set[s].parent:
              set[s].parent = Find(set[s:], set[s].parent)
          return set[s]</pre></code></p>
  
  <p><code>Merge</code> merges sets in the forest by finding them and promoting the higher ranked set.
  <pre><code>def Merge(set, value1, value2):
      set_val_1 = Find(set, value1)
      set_val_2 = Find(set, value2)
      if set_val_1.rank > set_val_2.rank:
          set_val_2.parent = set_val_1
      else:
          set_val_1.parent = set_val_2
          if set_val_1.rank == set_val_2.rank:
              set_val_2.rank += 1</pre></code></p>
  
  <p>I am getting some errors when I do <code>Find</code>s and <code>Merge</code>s, namely <code>Find</code> is not returning the proper set, and so I am not sure if <code>Merge</code> is working properly as well. I would appreciate some help to make sure the functions are implemented properly.</p>