@@ -0,0 +1,1087 @@
+package com.sunny.grokkingalgorithms.fasttrack.treesandgraphs;%0A%0Aimport com.sunny.grokkingalgorithms.ctci.c4.util.BinaryTreeNode;%0Aimport com.sunny.grokkingalgorithms.ctci.c4.util.TreeUtils;%0A%0A/**%0A * Created by sundas on 6/9/2018.%0A */%0Apublic class CheckIfTreesAreIndetical %7B%0A%0A  /*%0A  Check if two give binary trees are identical.%0A   */%0A%0A  /**%0A   *%0A   * @param root1%0A   * @param root2%0A   * @return%0A   */%0A  public static boolean isIdentical(BinaryTreeNode root1,BinaryTreeNode root2)%7B%0A    if(root1 == null && root2 == null)%7B%0A      return true;%0A    %7D%0A    /*%0A    One of them is null%0A     */%0A    if(root1 == null %7C%7C root2 == null)%7B%0A      return false;%0A    %7D%0A    if(root1.data != root2.data)%7B%0A      return false;%0A    %7D%0A    return (isIdentical(root1.left, root2.left) && isIdentical(root1.right,root2.right));%0A  %7D%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    BinaryTreeNode t1 = TreeUtils.createBST();%0A    System.out.println(isIdentical(t1,t1));%0A    BinaryTreeNode t2 = TreeUtils.createUnBalancedBinaryTree();%0A    System.out.println(isIdentical(t1,t2));%0A  %7D%0A%0A%7D%0A

Check If two tree are identical O(n).