- 2073 Bhadra · 6 marks
Draw binary tree from preorder and inorder
Short answer
Root is first preorder symbol F. In inorder E A C K F H D B G, left of F is E A C K, right is H D B G. Recurse: left subtree root A (preorder A E K C) has left E, right K with left C; right subtree root D has left H, right G with left B.
Draw a binary tree: Preorder F A E K C D H G B; In order E A C K F H D B G
Method: The first symbol of the preorder is the root of the tree. Find it in the inorder sequence: symbols to its left form the left subtree, those to its right form the right subtree. Repeat for each subtree using the matching part of the preorder.
Preorder: F A E K C D H G B
Inorder: E A C K F H D B G
| Step | Preorder part | Inorder part | Root | Left subtree (inorder) | Right subtree (inorder) |
|---|---|---|---|---|---|
| 1 | F A E K C D H G B | E A C K F H D B G | F | E A C K | H D B G |
| 2 | A E K C | E A C K | A | E | C K |
| 3 | K C | C K | K | C | – |
| 4 | D H G B | H D B G | D | H | B G |
| 5 | G B | B G | G | B | – |
Leaf nodes E, C, H and B are the single-symbol parts.
Binary tree
F
/ \
A D
/ \ / \
E K H G
/ /
C B
Verification
- Preorder: F A E K C D H G B ✓.
- Inorder: E A C K F H D B G ✓.
- Postorder (extra): E C K A H B G D F.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Binary tree traversals; preorder of BST · Data Structure and Algorithm, chapter 6
- Almost complete binary tree · Data Structure and Algorithm, chapter 6
- Strictly binary tree has 2n-1 nodes · Data Structure and Algorithm, chapter 6
- B-tree of order 5 for 82, 12, 22, ... · Data Structure and Algorithm, chapter 6 · asked 2×
- B-tree of order 5 for letters C N G A H ... · Data Structure and Algorithm, chapter 6 · asked 2×
- B-tree properties; order 5 for 3, 14, 7, ... · Data Structure and Algorithm, chapter 6 · asked 2×