Sorry, I misunderstood 'at most' in the question.
Thanks,
Balaji.
On Sat, Jan 15, 2011 at 11:27 AM, Decipher ankurseth...@gmail.com wrote:
@balaji - In the first tree , 9 has one only child which is not possible
for this question.
@juver++ - Can you give some algo for this problem
--
You
Two different binary trees can have same set of Leaves/Inner Nodes and same
Preorder traversal
5
/ \
3 10
/ \
1 9
\
7
5
/ \
3 9
/ / \
1
If it is a BST...then having a pre-order traversal can give us the unique
binary tree.
Also, as per the problem statement,
every node can have 0 or at most 2 nodes.
that means every node can have 0 or two childs, which is not the case below.
On Fri, Jan 14, 2011 at 6:49 PM, Balaji Ramani
@balaji_ramani
That is why there is additional info (L or N). So it is solvable during dfs.
--
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
If I am getting the question right, I believe both the above trees represent
this input:
5(N) 3(N) 1(L) 9(N) 7(L) 10(L)
5
/ \
3 10
/ \
1 9
\
7
5
/ \
3 9
I thought that node has 0 or 2 childs. If so, than supplied information is
enough.
If node may has 1 child, then it is failed.
--
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
@balaji - In the first tree , 9 has one only child which is not possible
for this question.
@juver++ - Can you give some algo for this problem
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@Decipher -
something like this:
void build_tree(Node* node, int index) {
node = new Node(value[index++]); // create an empty node
if (label[index] == 'L') return; // we are at leaf, there is no need to
process further current subtree
build_tree(node-left, index); // build left and right
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