sorry I didnt notice a great bug.
On 10/27/06, Arunachalam <[EMAIL PROTECTED]> wrote:
Deepak manohar's solution is an elegant one. This is very clumsy and you have a bug too.
On 10/27/06, sivaramakrishna kantharao < [EMAIL PROTECTED]> wrote:hihow abt the following oneint IsIsomorphic(tree *temp1,tree *temp2)
{
if(temp1==NULL && temp2==NULL)
return 1;
else if(temp1!=NULL && temp2!=NULL){>> It is either or dude.
return ((temp1->data="" &&( (same(temp1->left,temp2->left)
&&same(temp1->right,temp2->right) )
|| ( (same(temp1->left,temp2->right)
&&same(temp1->right,temp2->left)
));
}
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.
want to know more about me
http"//ww.livejournal.com/users/arunachalam
--
===================================
want to know more about me
http"//ww.livejournal.com/users/arunachalam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---
- [algogeeks] Re: isomorphism Ioannis Atsonios
- [algogeeks] Re: isomorphism Karthik Singaram L
- [algogeeks] Re: isomorphism Deepak Manohar
- [algogeeks] Re: isomorphism None
- [algogeeks] Re: isomorphism None
- [algogeeks] Re: isomorphism Karthik Singaram L
- [algogeeks] Re: isomorphis... None
- [algogeeks] Re: isomor... Karthik Singaram L
- [algogeeks] Re: isomor... sivaramakrishna kantharao
- [algogeeks] Re: isomor... Arunachalam
- [algogeeks] Re: isomor... Arunachalam
Reply via email to
