The position of the element in the postorder traversal of is . (answer in integer)
Note: The position begins with .
View worked solution
Answer: 7 : 7
To find the position of the element in the postorder traversal, we first reconstruct the Binary Search Tree (BST) from the given preorder traversal: 50, 25, 13, 40, 30, 47, 75, 60, 70, 80, 77.
In a BST, the first element of the preorder traversal is the root, elements smaller than the root form the left subtree, and elements larger form the right subtree. Following this recursively, we reconstruct the tree:
- Root:
- Left Subtree (elements < 50): Preorder
25, 13, 40, 30, 47- Root is . Left child is . Right subtree is
40, 30, 47(Root , Left , Right ).
- Root is . Left child is . Right subtree is
- Right Subtree (elements > 50): Preorder
75, 60, 70, 80, 77- Root is . Left subtree is
60, 70(Root , Right ). Right subtree is80, 77(Root , Left ).
- Root is . Left subtree is
- Left Subtree (elements < 50): Preorder
Now, we find the postorder traversal ():
- Postorder of Left Subtree (rooted at 25):
- Postorder of Right Subtree (rooted at 75):
- Left child (rooted at 60):
- Right child (rooted at 80):
- Combined:
- Postorder of entire tree (rooted at 50):
Counting the positions from left to right (1-indexed):
| Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Element | 13 | 30 | 47 | 40 | 25 | 70 | 60 | 77 | 80 | 75 | 50 |
Thus, the position of the element is .
Free practice · Your answers on this page are not saved.
