- 2069 Bhadra · 6 marks
Preorder and postorder of a BST
Short answer
Insert keys 52,38,40,27,20,66,55,46,60,26,5,68,23,54 in order into an initially empty BST. Preorder (NLR): 52, 38, 27, 20, 5, 26, 23, 40, 46, 66, 55, 54, 60, 68. Postorder (LRN): 5, 23, 26, 20, 27, 46, 40, 38, 54, 60, 55, 68, 66, 52.
Show the sequence of nodes in preorder and postorder traversal in the BST formed by 52, 38, 40, 27, 20, 66, 55, 46, 60, 26, 5, 68, 23, 54.
Build the BST by inserting the keys in the given order; each key goes left if smaller, right if larger.
The BST
52
├─L:38
│ ├─L:27
│ │ └─L:20
│ │ ├─L:5
│ │ └─R:26
│ │ └─L:23
│ └─R:40
│ └─R:46
└─R:66
├─L:55
│ ├─L:54
│ └─R:60
└─R:68
Preorder (root, left, right)
52, 38, 27, 20, 5, 26, 23, 40, 46, 66, 55, 54, 60, 68
Postorder (left, right, root)
5, 23, 26, 20, 27, 46, 40, 38, 54, 60, 55, 68, 66, 52
Check: inorder = 5, 20, 23, 26, 27, 38, 40, 46, 52, 54, 55, 60, 66, 68 (sorted), and the root 52 is first in preorder and last in postorder.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- B-tree of order 3 for 52, 46, 27, ... · Data Structure and Algorithm, chapter 6
- Binary tree traversals; preorder of BST · Data Structure and Algorithm, chapter 6
- Merge sort on 47, 27, 56, 23, ... · Data Structure and Algorithm, chapter 7
- AVL tree for 52, 65, 72, 15, 11, 32, 20 · Data Structure and Algorithm, chapter 6
- AVL tree for 10 20 30 50 45 40 8 5 3 · Data Structure and Algorithm, chapter 6
- BST insertion algorithm · Data Structure and Algorithm, chapter 6
- Partial r12.3 and multiple R1.23 (0.59, 0.46, 0.77) · Probability and Statistics, chapter 5 · asked 3×
- Design: 280 m head plant, 66 kV · Power Plant Design, chapter 4 · asked 12×
- Subnet 10.10.10.0/24 for 5, 16, 23, 27 · Computer Networks and Security, chapter 4 · asked 2×
- Design: 250 m head plant, 66 kV double circuit · Power Plant Design, chapter 4 · asked 13×