The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16,…
2024
The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the postorder traversal of the tree?
- A.
20, 19, 18, 16, 15, 12, 11, 10
- B.
11, 12, 10, 16, 19, 18, 20, 15
- C.
19, 16, 18, 20, 11, 12, 10, 15
- D.
More than one of the above
- E.
None of the above
Attempted by 323 students.
Show answer & explanation
Correct answer: B
Step 1: In preorder traversal, the first element is the root of the tree. So, 15 is the root.
Step 2: All elements less than 15 form the left subtree: 10, 12, 11. All elements greater than 15 form the right subtree: 20, 18, 16, 19.
Step 3: For the left subtree (10, 12, 11): 10 is the root. 12 is greater than 10, so it is the right child. 11 is less than 12 but greater than 10, so it is the left child of 12.
Step 4: For the right subtree (20, 18, 16, 19): 20 is the root. 18 is less than 20, so it is the left child. 16 is less than 18, so it is the left child of 18. 19 is greater than 18, so it is the right child of 18.
Step 5: Postorder traversal visits left subtree, then right subtree, then root.
Step 6: Left subtree postorder: 11 (left), 12 (right), 10 (root) → 11, 12, 10.
Step 7: Right subtree postorder: 16 (left), 19 (right), 18 (root), 20 (root) → 16, 19, 18, 20.
Step 8: Combine: left postorder + right postorder + root → 11, 12, 10, 16, 19, 18, 20, 15.
हिन्दी उत्तर: प्रीऑर्डर ट्रैवर्सल में पहला तत्व रूट होता है। इसलिए 15 रूट है। 15 से छोटे तत्व बाएँ उप-ट्री में होंगे: 10, 12, 11। 15 से बड़े तत्व दाएँ उप-ट्री में होंगे: 20, 18, 16, 19।
बाएँ उप-ट्री (10, 12, 11) के लिए: 10 रूट है। 12, 10 से बड़ा है, इसलिए यह दाएँ बच्चा है। 11, 12 से छोटा है लेकिन 10 से बड़ा है, इसलिए यह 12 का बाएँ बच्चा है।
दाएँ उप-ट्री (20, 18, 16, 19) के लिए: 20 रूट है। 18, 20 से छोटा है, इसलिए यह बाएँ बच्चा है। 16, 18 से छोटा है, इसलिए यह 18 का बाएँ बच्चा है। 19, 18 से बड़ा है, इसलिए यह 18 का दाएँ बच्चा है।
पोस्टऑर्डर ट्रैवर्सल बाएँ उप-ट्री, फिर दाएँ उप-ट्री, फिर रूट को देखता है।
बाएँ उप-ट्री का पोस्टऑर्डर: 11 (बाएँ), 12 (दाएँ), 10 (रूट) → 11, 12, 10।
दाएँ उप-ट्री का पोस्टऑर्डर: 16 (बाएँ), 19 (दाएँ), 18 (रूट), 20 (रूट) → 16, 19, 18, 20।
संयुक्त: बाएँ पोस्टऑर्डर + दाएँ पोस्टऑर्डर + रूट → 11, 12, 10, 16, 19, 18, 20, 15।