Check if two binary trees are same or not

suggest change
  1. For example if the inputs are:

Example:1

a)

b)

Output should be true.

Example:2

If the inputs are:

a)

b)

Output should be false.

Pseudo code for the same:

boolean sameTree(node root1, node root2){

if(root1 == NULL && root2 == NULL)
return true;

if(root1 == NULL || root2 == NULL)
return false;

if(root1->data == root2->data 
     && sameTree(root1->left,root2->left)
        && sameTree(root1->right, root2->right))
return true;

}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents