title: Height of a binary tree
body: <p>Consider the following code:</p>
  
  <pre><code>public int heightOfBinaryTree(Node node)
  {
      if (node == null)
      {
          return 0;
      }
      else
      {
          return 1 +
          Math.max(heightOfBinaryTree(node.left),
              heightOfBinaryTree(node.right));
      }
  }
  </code></pre>
  
  <p>I want to know the logical reasoning behind this code. How did people come up with it? Does some have an inductive proof?</p>
  
  <p>Moreover, I thought of just doing a BFS with the root of the binary tree as the argument to get the height of the binary tree. Is the previous approach better than mine?Why?</p>