Hi,
bool issymmetric(node* root)
{
return ismirror(root,root);
}
bool ismirror(node* root1,node* root2)
{
if(!root1 || !root2) return root1==NULL root2==NULL;
return root1-data==root2-data ismirror(root1-left,root2-right)
ismirror(root1-right,root2-left);
}
--
You received this
recurse on left and right will do it and keep comparing the values
On Tue, May 22, 2012 at 2:50 PM, atul anand atul.87fri...@gmail.com wrote:
no need of creating another mirror tree
you just need to call the function func(root-left,root-right);
now left sub tree and right sub tree will be
Create the mirror copy of the tree and compare with original. If same then
symmetric.
On Tue, May 22, 2012 at 10:50 AM, algogeek dayanidhi.haris...@gmail.comwrote:
How to check if a given binary tree is structurally symmetric ie. the
left sub tree should be mirror image of right sub tree and
no need of creating another mirror tree
you just need to call the function func(root-left,root-right);
now left sub tree and right sub tree will be considered as if you are
checking 2 different trees
same code to check if 2 tree are structurally similar will work.
On Tue, May 22, 2012 at 10:50
okay thanks... :-)
On Tue, May 22, 2012 at 2:50 PM, atul anand atul.87fri...@gmail.com wrote:
no need of creating another mirror tree
you just need to call the function func(root-left,root-right);
now left sub tree and right sub tree will be considered as if you are
checking 2 different
How to check if a given binary tree is structurally symmetric ie. the
left sub tree should be mirror image of right sub tree and vice-versa.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to