27 votes 27 votes A binary search tree contains the numbers $1, 2, 3, 4, 5, 6, 7, 8.$ When the tree is traversed in pre-order and the values in each node printed out, the sequence of values obtained is $5, 3, 1, 2, 4, 6, 8, 7.$ If the tree is traversed in post-order, the sequence obtained would be $8, 7, 6, 5, 4, 3, 2, 1$ $1, 2, 3, 4, 8, 7, 6, 5$ $2, 1, 4, 3, 6, 7, 8, 5$ $2, 1, 4, 3, 7, 8, 6, 5$ DS gateit-2005 data-structures binary-search-tree normal + – Ishrat Jahan asked Nov 3, 2014 edited Dec 20, 2017 by kenzou Ishrat Jahan 9.2k views answer comment Share Follow See 1 comment See all 1 1 comment reply Chhotu commented Oct 19, 2017 reply Follow Share For detailed explanation following link could be refered -> http://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/ 1 votes 1 votes Please log in or register to add a comment.
Best answer 32 votes 32 votes The answer is $D.$ Gate Keeda answered Nov 3, 2014 edited May 2, 2019 by Lakshman Bhaiya Gate Keeda comment Share Follow See all 0 reply Please log in or register to add a comment.
11 votes 11 votes Inorder of binary search tree is sorted input sequence so inorder= 1, 2, 3, 4, 5, 6, 7, 8. preorder= 5, 3, 1, 2, 4, 6, 8, 7. take 1st value from preorder and find its position in inorder sequence . by doing this u get binary search tree. after that find post order of tree. i.e. left child --> right child --> root node. Prashant. answered Nov 24, 2015 Prashant. comment Share Follow See all 0 reply Please log in or register to add a comment.
6 votes 6 votes Preorder Traversal= 5, 3, 1, 2, 4, 6, 8, 7 In BST Inorder Traversal is sorted input sequence so Inorder Traversal= 1, 2, 3, 4, 5, 6, 7, 8. Using these two traversals we can find the preorder traversal of the tree i.e., 2, 1, 4, 3, 7, 8, 6, 5 vishalgarg837 answered Nov 24, 2015 vishalgarg837 comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes Algorithm Preorder(tree) 1. Visit the root. 2. Traverse the left subtree, i.e., call Preorder(left-subtree) 3. Traverse the right subtree, i.e., call Preorder(right-subtree) Algorithm Postorder(tree) 1. Traverse the left subtree, i.e., call Postorder(left-subtree) 2. Traverse the right subtree, i.e., call Postorder(right-subtree) 3. Visit the root. Mudrakola Karthik 3 answered Jun 12, 2018 edited Jan 28, 2019 by Mudrakola Karthik 3 Mudrakola Karthik 3 comment Share Follow See 1 comment See all 1 1 comment reply rawan commented Jan 15, 2019 reply Follow Share What you have described is In-order, not Post-order. https://www.geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/ 0 votes 0 votes Please log in or register to add a comment.