Taking a Wild Stab at this problem:

This is like evaluating a prefix expression.

We know that an expression tree also has either 0 or 2 children and
the internal nodes are operators and leaf nodes are operands.

In a prefix expression we try to look for the pattern
"<operator><operand><operand>". If we find such a thing we evaluate it
and put a placeholder for it in the string.

Similarly for this, we look for the pattern NXX. where X is either L
or a placeholder for a partially constructed tree. Construct the tree
and replace in place of NXX a placeholder like L'. Repeat this and you
will have a tree.

Consider the following tree(Same from above comment)

N
/ \
N N
/ \ / \
N L N L
/ \ / \
L L L L
Prefix expression is
NNNLLLNNLLL
1st NXX pattern is:

NN(NLL)LNNLLL construct a tree for it and replace in the String as L'
to get NNL'LNNLLL

2nd NXX:

N(NL'L)NNLLL =>NL'NNLLL

3rd NXX:
NL'N(NLL)L => NL'NL'L

4th NXX
NL'(NL'L) => NL'L' (Final result)

Basically we are constructing the tree in a bottom up fashion.


On Jan 14, 10:20 am, Decipher <ankurseth...@gmail.com> wrote:
> A special type of tree is given, where all leaf are marked with L and others
> are marked with N. every node can have 0 or at most 2 nodes. Trees preorder
> traversal is given give a algorithm to build tree from this traversal.

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to