On Jun 27, 7:32 am, sharad kumar <[email protected]> wrote:
> Algorithm to find if a tree is symmetric? (The tree is a generalized tree
> with as many child nodes as possible)

Here's how to do it with a binary tree.  Extension to an n-ary tree is
straightforward.

boolean is(a, b)
{
  if (a == null && b == null) return true;
  if (a != null && b != null && a->key == b->key)
    return is(a->left, b->right) && is(a->right, b->left);
  return false;
}

-- 
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.google.com/group/algogeeks?hl=en.

Reply via email to