title: Time and space complexity of this function to print binary tree level by level
body: <p>This algorithm is for printing a common binary tree level by level.</p>
  
  <p>What is the time complexity and space complexity of <code>printSpecificLevel_BT()</code> and <code>printBT_LBL()</code>?</p>
  
  <p>I think <code>printSpecificLevel_BT</code>'s time complexity is <code>O(lg N)</code>, and space complexity is <code>O(lg N)</code>.<br>
  I think <code>printBT_LBL()</code>'s time complexity is <code>O((lgN)^2)</code>, and the space complexity is <code>O((lgN)^2)</code>.</p>
  
  <p>Is this correct?</p>
  
  <pre><code>// Print the specific level of a binary tree.
  public static void printSpecificLevel_BT (Node root, int level) {
      if (root == null) return;
      if (level == 0) System.out.print(String.format("%-6d", root.data)); // Base case.
      // Do recrusion.
      printSpecificLevel_BT(root.leftCh, level - 1);
      printSpecificLevel_BT(root.rightCh, level - 1);
  }
  
  // Get the height of a binary tree.
  public static int getHeight_BT (Node root) {
      if (root == null || (root.leftCh == null &amp;&amp; root.rightCh == null)) return 0; // Base case.
      return 1 + Math.max (getHeight_BT(root.leftCh), getHeight_BT(root.rightCh));
  }
  
  // Print a binary tree level by level.
  public static void printBT_LBL (Node root) {
      // Get the height of this binary tree.
      int height = getHeight_BT(root);
      for (int i = 0; i &lt;= height; i ++) {
          printSpecificLevel_BT(root, i);
          System.out.println();
      }
  }
  </code></pre>