/*
 * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.pedrovgs.problem65;

/**
 * Implement a function to check if a binary tree is balanced. For the purposes of this question, a
 * balanced tree is defined to be a tree such that the heights of the two subtrees of any node
 * never differ by more than one.
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class IsTreeBalanced {
  
}

@@ -645,16 +645,67 @@
 lem65;%0A%0A
+import com.github.pedrovgs.binarytree.BinaryNode;%0A%0A
 /**%0A * I
@@ -1010,9 +1010,895 @@
 d %7B%0A
+%0A
   
+/**%0A   * Recursive algorithm to check if a binary tree is balanced. The complexity order in time terms%0A   * of this algorithm is equals to O(N) where N is the number of nodes in the binary tree. In%0A   * space terms, the complexity order is O(1) because we are not using any auxiliary data%0A   * structure to resolve this problem. This algorithm is based on the tree height because the%0A   * balanced tree definition is based on this.%0A   */%0A  public boolean check(BinaryNode root) %7B%0A    if (root == null) %7B%0A      return true;%0A    %7D else %7B%0A      int heightDifference = getRootHeight(root.getLeft()) - getRootHeight(root.getRight());%0A      return Math.abs(heightDifference) %3C= 1;%0A    %7D%0A  %7D%0A%0A  private int getRootHeight(BinaryNode tree) %7B%0A    if (tree == null) %7B%0A      return 0;%0A    %7D else %7B%0A      return 1 + Math.max(getRootHeight(tree.getLeft()), getRootHeight(tree.getRight()));%0A    %7D%0A  %7D
 %0A%7D%0A

Add solution to problem 65