title: Counting number of nodes in a Binary Search Tree
body: <p>I am trying to print the size of my binary search tree. However, what my code is doing now is printing what level each node is at. I feel as though I am putting my <code>count += 1</code> in the wrong place or perhaps it might be something else. I was wondering if someone could be an extra set of eyes for me and give me a hint on how I can fix this.</p>
  
  <p>output:</p>
  
  <pre><code>3
  3
  2
  3
  3
  2
  1
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>7
  </code></pre>
  
  <p>my code:</p>
  
  <pre><code>def BST_size(root, count = 0):
      if root is None:
          print "size -1 (Null value in root)"
      if root is not None:
          count += 1
          if root.left is not None:
              BST_size(root.left, count)
          if root.right is not None:
              BST_size(root.right, count)
      print count 
  </code></pre>
  
  <p>Extra parts:</p>
  
  <pre><code>class Node:
      def __init__(self,value):
          self.right = None
          self.left = None
          self.value = value
  
  
  def BST_Insert(root, node):     # root --&gt; root of tree or subtree!
      if root.value is None:
          root = node             # beginning of tree
      else:
          if root.value &gt; node.value:     # go to left
              if root.left is None:
                  root.left = node
              else:
                  BST_Insert(root.left, node)
  
          if root.value &lt; node.value:    # go to right
              if root.right is None:
                  root.right = node
              else:
                  BST_Insert(root.right, node)
  
  r = Node(4)
  # left
  a = Node(2)
  b = Node(1)
  c = Node(3)
  # right
  d = Node(8)
  e = Node(6)
  f = Node(10)
  
  BST_Insert(r, a)
  BST_Insert(r, b)
  BST_Insert(r, c)
  BST_Insert(r, d)
  BST_Insert(r, e)
  BST_Insert(r, f)
  </code></pre>