title: Binary Tree Size function in Python
body: <p>I have written a couple of functions to calculate size of binary tree. The first one (Function 1) works perfectly fine and is declared outside the class, it is not a member function of the class. However the second one which is the member function of the class is giving me weird results. I am confused! Any help would be appreciated.</p>
  
  <pre><code>Function 1
      def size(root):
          if root is None:
              return 0
          else:
              return size(root.left)+ 1+ size(root.right)
  
  
  Function 2
      def size(self):
          if self.left is None or self.right is None:
                return 0
          else:
                return self.left.size()+1+self.right.size()
  </code></pre>