Adobe Interview Question
Not necessarily BST,
int sameTrees(Node* a, Node*b)
{
if (a == null && b == null) return (true);
else if (a !=null && b != null)
return ((a->data == b->data)&& (sameTree(a->left,b->left) && (sameTree(a->right, b->right)));
else
return false;
This is *not* correct. You cannot assume that the trees are structured exactly the same way. The keys for two trees could be identical but the way they are structured may be different.
Do inorder traversal of the first tree and hash the keys. Now do inorder traversal of the second tree and make sure that all the keys encountered belong in the hash table.
I believe you mean two binary "search" trees?
- Anonymous March 11, 2010