1,007 views

1 Answer

1 votes
1 votes

Given a binary tree with preorder(Root-Left-Right): $1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \ 8 $, in addition to this a right pointer is also given for some nodes.

right child of 1 is 6, right child of 2 is 5, right child of 3 is 4, right child of 6 is 7

From the given data we can try making binary tree

From i) and iv) we can get 

 In preorder we have 1 in starting so obviously 1 is the root of the tree, next to 1 we have 2 that means 2 is in the left subtree of 1 and coming to 3, it is in the left subtree of 2, we know nothing about 8 but if we see it is in the end of preorder which means it is node which is traversed last in right subtree, it is traversed after 7 it can be either left child or right child of 7.

From the above observations we get

Here we can observe one more thing it is BST and we know preorder of BST is in ascending order, but this is not unique tree we can make one more tree as 

We can calculate post order of any of the tree which is $4\ 3\ 5\ 2\ 8\ 7\ 6\ 1$

Hence option c) is the correct answer


NOTE:

We have Preorder and Postorder, so it may be possible that that we we will not get a unique tree but any traversal is always unique for every different tree we make from preorder and post order.

Inorder + Preorder/Postorder always results unique tree

Related questions

0 votes
0 votes
1 answer
1
sripo asked Nov 8, 2018
668 views
For a heap containing n elements,smallest element can be found in n/2 operations.I always get confused and think as logn operations.Please help me differentiating between...
1 votes
1 votes
0 answers
3
Rohit Gupta 8 asked Dec 25, 2017
1,137 views
If the average depth of a node in an $n$-node binary search tree is $O(\log{n})$, then the height of the tree is$O(n\log{n})$$O(n)$$O(\log{n})$$O(\sqrt(n\log{n}))$
0 votes
0 votes
2 answers
4
Aman Bisht asked Jun 12, 2017
1,119 views
The height of a binary tree having 'i' nodes at level 'i' considering root to be at level 1 is . where 'n' is the total no of nodes in the tree.A. O(logn)B. O(n)C. O(R...