Tree isomorphism

Given two  trees and ignoring the content of the nodes, describe rules that would define whether or not these two trees are equivalent.

C++:
01 bool treeEqual(Node* a, Node* b)
02 {
03     if(a!=NULL){
04         if(b==NULL)
05             return false;
06         return (treeEqual(a->left,b->left)&&
07                 treeEqual(a->right,b->right));
08     }
09     else
10         return (b==NULL);
11 }
Advertisements
This entry was posted in Tree. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s