Discussion
Given a binary tree with :
(i) The inorder tree traversal output as : A B C D
(ii) The preorder tree traversal output as : C B A D
Then the original binary tree is :
Answer: C
The tree has root C, with B as its left child, D as its right child, and A as the left child of B.
Preorder lists the root first, so C is the root. In the inorder sequence A B C D, everything before C (A, B) is in the left subtree and D is in the right subtree. In the left subtree the preorder is B A, so B is its root, and A comes before B in inorder, so A is B's left child.
Check: inorder A B C D and preorder C B A D both match. The trees rooted at A would give a preorder starting with A, so options A, B and D are wrong.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development