I was trying to find a solution for checking the symmetry of a tree.
I would like to get some comments on the approach.. I am trying to do it by modifying the inorder traversal thing..
The pseudo code is:
// since the structure should be similar
string in1,in2;
func inorder (root): //normal inorder traversal
static int i;
if root==NULL: return;
if (root->left!=NULL):
in1[i++] = 'L';
inorder(root->left);
if (root->right!=NULL):
in1[i++] = 'R';
inorder(root->right);
func modified_inorder (root):
// modified inorder traversal. This one flips the traversal order from (root,left,right) to (root,right,left).
static int i;
if root==NULL: return;
if (root->right!=NULL):
in1[i++] = 'L';
inorder(root->right);
if (root->left!=NULL):
in1[i++] = 'R';
inorder(root->left);
string_compare(in1,in2); //this should provide the result by comparing the strings formed by traversals.
Now, would this work?