The preorder traversal sequence of a binary search tree is . Which one of the following is the postorder traversal sequence of the same tree?
View worked solution
Answer: D
For any Binary Search Tree (BST), the inorder traversal is always the sorted sequence of its keys in ascending order.
Given the preorder traversal:
Preorder:
Sorting these keys gives the inorder traversal:
Inorder:
Step 1: Reconstructing the BST
- The first element in the preorder sequence is the root: .
- Elements smaller than () form the left subtree. Elements larger than () form the right subtree.
- For the left subtree, the next element in the preorder sequence is , which becomes the root of this subtree.
- Keys smaller than () go to its left.
- Keys larger than () go to its right.
- Continuing this process recursively, we construct the unique BST:
30
/ \
20 39
/ \ / \
10 25 35 42
\ /
15 23
Step 2: Finding the Postorder Traversal
Postorder traversal visits nodes in the order: Left Right Root.
- Left Subtree of :
- Postorder of left child :
- Left child of (rooted at ):
- Right child of (rooted at ):
- Root:
- Postorder of left child :
- Right Subtree of :
- Postorder of right child :
- Left child:
- Right child:
- Root:
- Postorder of right child :
- Root Node:
Combining these, the complete postorder traversal is:
This matches Option D.
Free practice · Your answers on this page are not saved.
