Recursive Post Order Tree Navigation
<p>I am trying to implement the following algorithm:</p>

<blockquote>
  <p>Fitch’s algorithm (for a one-character sequence): </p>
  
  <p>Step 1: For each leaf node n, create a set Sn containing the leaf’s
  assigned letter. </p>
  
  <p>Step 2: For each interior node n with children u and v, create a set
  Sn equal to: • Su ∩ Sv if Su ∩ Sv is not empty. • Su U Sv if Su ∩ Sv is
  empty. </p>
  
  <p>Step 3: For each interior node n with parent p, assign n.seq a
  character equal to: • p.seq if p.seq ∈ Sn • Any character of Sn
  otherwise (or if n is the root).</p>
</blockquote>

<p>I am given a binary tree as the input.</p>

<p>I have completed step one and now need to recursively do postorder navigation through the binary tree to assign sets to every nodes. I am wondering how to start this?</p>

<p>Navigating through the tree using preorder recursion is done as such (this is just an example calculating the length of the tree which is decided by how many leafs are in the tree. leafs = no children):</p>

<pre><code>def __len__(self):

     if self.isLeaf():
        print('base case - reached leaf!')
        return 1

    for t,w in self.children:  
        print('not leaf so sent through loop')
        numLeaves += len(t)

    return numLeaves
</code></pre>
