23 votes 23 votes Which one of the following binary trees has its inorder and preorder traversals as $BCAD$ and $ABCD$, respectively? DS gateit-2004 binary-tree easy data-structures + – Ishrat Jahan asked Nov 2, 2014 edited May 1, 2021 by gatecse Ishrat Jahan 4.9k views answer comment Share Follow See 1 comment See all 1 1 comment reply smsubham commented Nov 13, 2020 reply Follow Share In Preorder 1st element is root and everything to left of it in inorder is in LST and right is in RST. So A is root with BC in LST and D in RST. Option A,C eliminated. From BC, in preorder B is first so it should be the root. B is elminnated. So answer is D. Also as C is after it in inorder it should be in RST(with B as root). So D would be correct. 1 votes 1 votes Please log in or register to add a comment.
Best answer 28 votes 28 votes Answer is D. Inorder traversal is left node right. Preorder is node left right. Sankaranarayanan P.N answered Nov 14, 2014 edited Jun 13, 2018 by Milicevic3306 Sankaranarayanan P.N comment Share Follow See all 4 Comments See all 4 4 Comments reply Arjun commented Nov 14, 2014 reply Follow Share D is correct rt? 1 votes 1 votes Sankaranarayanan P.N commented Nov 14, 2014 reply Follow Share ya D is correct. mistake edited in the answer :) 0 votes 0 votes Puja Mishra commented Dec 24, 2017 reply Follow Share Try it .. 0 votes 0 votes Kiyoshi commented Apr 26, 2021 reply Follow Share @Puja Mishra I have seen this figure on 3 questions. In how many questions same figure. 2 votes 2 votes Please log in or register to add a comment.
3 votes 3 votes Inorder traversal 1) Traverse the left subtree 2) Visit the root 3) Traverse the right subtree Preorder traversal 1) Visit the root 2) Traverse the left subtree 3) Traverse the right subtree Bhagirathi answered Nov 20, 2014 Bhagirathi comment Share Follow See all 0 reply Please log in or register to add a comment.
3 votes 3 votes ans is d in order left-root-right preorder root-left right after applying above formula we get exactly what they asking so d is correct Abhimanyu Kumar answered Nov 20, 2014 Abhimanyu Kumar comment Share Follow See all 0 reply Please log in or register to add a comment.
2 votes 2 votes By this way we can create tree and Check options so option D is answer Rishi yadav answered Oct 5, 2017 Rishi yadav comment Share Follow See all 0 reply Please log in or register to add a comment.