hi
how abt the following one
 
int IsIsomorphic(tree *temp1,tree *temp2)
{
 if(temp1==NULL && temp2==NULL)
  return 1;
 else if(temp1!=NULL && temp2!=NULL){
  return ((temp1->data="" && same(temp1->left,temp2->left)
                                                             &&same(temp1->right,temp2->right));
 }
 else
  return 0;    
}
 
Plz correct me, incase of errors.
 
regards.
 
 
On 10/27/06, Karthik Singaram L <[EMAIL PROTECTED]> wrote:
His code works because he calls the isIsomorphic on the left and right childs without comparing their values, which you were doing in your code before calling the isIsomorphism

your code:
if(node1.leftChild.value == node2.leftChild.value)
      isIsomorphic(node1.leftChild, node2.leftChild)

his code:
  if (node1->value != node2->value) /* Check on node values not child */
           return 0;
       if (isIsomorphic(node1->left, node2->left) && isIsomorphic(node1->right, node2->right))
              return 1;
       if (isIsomorphic(node1->right, node2->left) && isIsomorphic(node1->left, node2->right))
              return 1;



The part on "return node1 == null && node2 == null; " is needed because
what if node1 and node2 are both null elements (this happens when isIsomorphic is called on leaves).
The reason for the && condition is that what if one tree has a leaf in that position and the other tree has a node in that position, in which case we must return non-isomorphic. If both the nodes are null we must return that they are isomorphic.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to