title: Binary Tree Nodes - Which Way?
body: <p>For an assignment we were given in Data Structures, we had to create a test class to determine whether the code we were given correctly traversed the binary trees in our test class.</p>
  
  <p>These are the 3 constructors for BinaryTreeNode class that was given to us:</p>
  
  <pre><code>public BinaryTreeNode(Object theElement, BinaryTreeNode theleftChild, BinaryTreeNode therightChild)
  {
      element = theElement;
      leftChild = theleftChild;
      rightChild = therightChild;
  }
  
  public BinaryTreeNode(Object theElement)
  {
      element = theElement;
  }
  
  public BinaryTreeNode() {} 
  </code></pre>
  
  <p>I quickly made the following in my test class to create one of the trees specified:</p>
  
  <pre><code>// tree for ( A - B ) / C
  BinaryTreeNode b1 = new BinaryTreeNode("A");
  BinaryTreeNode b2 = new BinaryTreeNode("-");
  BinaryTreeNode b3 = new BinaryTreeNode("B");
  BinaryTreeNode b4 = new BinaryTreeNode("/");
  BinaryTreeNode b5 = new BinaryTreeNode("C");
  BinaryTreeNode bAB = new BinaryTreeNode(b2, b1, b3);
  BinaryTreeNode bRoot = new BinaryTreeNode(b4, bAB, b5);
  q.put(bRoot);
  </code></pre>
  
  <p>However, my friend suggested I do it this way:</p>
  
  <pre><code>// tree for ( A - B ) / C
  BinaryTreeNode b1 = new BinaryTreeNode("A");
  BinaryTreeNode b2 = new BinaryTreeNode("B");
  BinaryTreeNode b3 = new BinaryTreeNode("C");
  BinaryTreeNode bRoot= new BinaryTreeNode("/", new BinaryTreeNode("-", b1, b2), b3);
  q.put(bRoot);
  </code></pre>
  
  <p>However, he had a tough time explaining why this way was better.  Could anybody explain why this is more efficient? If more code is needed from the example, just ask.</p>