---
title: "Preorder and postorder of a BST"
subject: "Data Structure and Algorithm"
chapter: 6
key: "semester_4/data_structure_and_algorithm:bst-preorder-postorder-52-38"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/bst-preorder-postorder-52-38
site: BCT Engineering
---

# Preorder and postorder of a BST

Data Structure and Algorithm · Chapter 6: Trees

- Asked in: 2069 Bhadra, 6 marks
- Video: [Lec-56: Preorder, Inorder and Postorder in 5 minute | Tree Traversal | Easiest and Shortest Trick](https://www.youtube.com/watch?v=XRcC7bAtL3c) — Gate Smashers
- 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/bst-preorder-postorder-52-38
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-6

## Question

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.

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

## Answer

Build the BST by inserting the keys in the given order; each key goes left if smaller, right if larger.

#### The BST
```text
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.

## Check yourself

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

1. How is the BST built from the given keys?
   A. Insert in the given order; smaller goes left and larger goes right
   B. Sort first then insert
   C. Insert from the end
   D. Median is the root
   Answer: A. Each key follows the BST ordering rule in the order given. (Key point: Build rule)

2. Where does 26 go?
   A. Left child of 20
   B. Left child of 27
   C. Right child of 20
   D. Right child of 38
   Answer: C. 26 < 38 < ... 26 < 27, 26 > 20, so it is the right child of 20. (Key point: Position of 26)

3. How does preorder start and what pattern is shown?
   A. 52, 38, 27, 20, ...; root first
   B. 5, 23, 26, ...; root last
   C. 20, 5, 26, ...
   D. 68, 66, 55, ...
   Answer: A. Preorder visits the root first, then the left subtree. (Key point: Preorder start)

4. What is the first and last node in postorder?
   A. First 52, last 5
   B. First 68, last 5
   C. First 5, last 52 (root)
   D. First 5, last 68
   Answer: C. Postorder visits leaves of the left subtree first and the root last. (Key point: Postorder)

## Related in Data Structure and Algorithm

- [B-tree of order 3 for 52, 46, 27, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abtree-order3-52-46-27) — Data Structure and Algorithm, chapter 6
- [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
- [Merge sort on 47, 27, 56, 23, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Amerge-sort-trace-47-27) — Data Structure and Algorithm, chapter 7
- [AVL tree for 52, 65, 72, 15, 11, 32, 20](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-52-65-72) — Data Structure and Algorithm, chapter 6
- [AVL tree for 10 20 30 50 45 40 8 5 3](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30) — Data Structure and Algorithm, chapter 6
- [BST insertion algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abst-insertion-algorithm) — Data Structure and Algorithm, chapter 6

## Related in other subjects

- [Partial r12.3 and multiple R1.23 (0.59, 0.46, 0.77)](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Apartial-multiple-corr-r12-059) — Probability and Statistics, chapter 5, asked 3×
- [Design: 280 m head plant, 66 kV](https://www.bctengineer.com/question.md?key=semester_8%2Fpower_plant_design%3Adesign-2075-280m-66kv) — Power Plant Design, chapter 4, asked 12×
- [Subnet 10.10.10.0/24 for 5, 16, 23, 27](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Asubnetting-10-10-10-0) — Computer Networks and Security, chapter 4, asked 2×
- [Design: 250 m head plant, 66 kV double circuit](https://www.bctengineer.com/question.md?key=semester_8%2Fpower_plant_design%3Adesign-2071-250m-0-92mh) — Power Plant Design, chapter 4, asked 13×
