Re: [algogeeks] Building A Special Tree

2011-01-15 Thread Balaji Ramani
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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread Balaji Ramani
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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread vaibhav agrawal
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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread juver++
@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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread Balaji Ramani
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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread juver++
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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread Decipher
@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

Re: [algogeeks] Building A Special Tree

2011-01-14 Thread juver++
@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

[algogeeks] Building A Special Tree

2011-01-13 Thread Decipher
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