---
title: "Draw binary tree from preorder and inorder"
subject: "Data Structure and Algorithm"
chapter: 6
key: "semester_4/data_structure_and_algorithm:draw-tree-from-preorder-inorder"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/draw-tree-from-preorder-inorder
site: BCT Engineering
---

# Draw binary tree from preorder and inorder

Data Structure and Algorithm · Chapter 6: Trees

- Asked in: 2073 Bhadra, 6 marks
- Video: [5.7 Construct Binary Tree from Preorder and Inorder Traversal | Example | Data Structures Tutorials](https://www.youtube.com/watch?v=PoBGyrIWisE) — Jenny's Lectures CS IT
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/draw-tree-from-preorder-inorder
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-6

## Question

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

## 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.

## Answer

**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
```text
            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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How is the root found?
   A. Last symbol of preorder
   B. Middle of inorder
   C. First symbol of preorder (F)
   D. First symbol of inorder
   Answer: C. Preorder visits the root first. (Key point: Root)

2. How is the left subtree found?
   A. Symbols left of F in inorder: E A C K
   B. H D B G
   C. E A C K F
   D. Symbols after F in preorder
   Answer: A. Inorder puts left subtree before the root. (Key point: Splitting)

3. What are the roots of the left and right subtrees?
   A. E and H
   B. K and G
   C. A and D
   D. C and B
   Answer: C. The next unused preorder symbols for each part are A and D. (Key point: Subtree roots)

4. What is the position of C and B?
   A. C is left child of K; B is left child of G
   B. C is right child of K
   C. B is right child of G
   D. C is left of A
   Answer: A. In inorder C comes before K, and B comes before G. (Key point: Shape)

## Related in Data Structure and Algorithm

- [Binary tree traversals; preorder of BST](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abinary-tree-traversal-methods-preorder) — Data Structure and Algorithm, chapter 6
- [Almost complete binary tree](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aalmost-complete-binary-tree) — Data Structure and Algorithm, chapter 6
- [Strictly binary tree has 2n-1 nodes](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Astrict-binary-tree-nodes-proof) — Data Structure and Algorithm, chapter 6
- [B-tree of order 5 for 82, 12, 22, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abtree-order5-82-12-22) — Data Structure and Algorithm, chapter 6, asked 2×
- [B-tree of order 5 for letters C N G A H ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abtree-order5-cngahekq) — Data Structure and Algorithm, chapter 6, asked 2×
- [B-tree properties; order 5 for 3, 14, 7, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abtree-properties-order5-3-14) — Data Structure and Algorithm, chapter 6, asked 2×
