title: How to count children in a tree
body: <p>I have a list of numbers:</p>
  
  <pre><code>[1, 2, 3, 4, 5, 6, 7]
  </code></pre>
  
  <p>I'm interested in finding an algorithm that can sum the total children in this list if the list where a tree:</p>
  
  <pre><code>                              1
                              /   \
                             2     3
                            / \   / \
                           4   5 6   7
  </code></pre>
  
  <p>I'm looking for an algorithm that would give:</p>
  
  <pre><code>[6, 2, 2, 0, 0, 0, 0]
  
  
  A = 6
  B = 2
  C = 2
  D = 0
  E = 0
  F = 0
  G = 0
  </code></pre>
  
  <p>Each node (except the leaves) has two children. The only exception is if the list if even:</p>
  
  <pre><code>                              1
                              /   \
                             2     3
                            / \   / 
                           4   5 6   
  </code></pre>
  
  <p>I would like to avoid building a tree and then counting the number of children at each node. There must be a simple mathematical way to count the number of children from a list?</p>