---
title: "Solve TOH for 3 disks"
subject: "Data Structure and Algorithm"
chapter: 5
key: "semester_4/data_structure_and_algorithm:toh-3-disks-steps"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/toh-3-disks-steps
site: BCT Engineering
---

# Solve TOH for 3 disks

Data Structure and Algorithm · Chapter 5: Recursion

- Asked in: 2071 Bhadra, 4 marks; 2069 Bhadra, 4 marks (asked 2 times)
- Video: [Tower of Hanoi Problem - Made Easy](https://www.youtube.com/watch?v=q6RicK1FCUs) — Abdul Bari
- 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/toh-3-disks-steps
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-5

## Question

Explain the TOH problem and show the steps to solve it using recursion for 3 disks.

## Short answer

For 3 disks (1 smallest, 3 largest) from A to C using B: move 1 A→C, 2 A→B, 1 C→B, 3 A→C, 1 B→A, 2 B→C, 1 A→C. This follows the recursive pattern: top 2 to B, largest to C, then 2 to C. Total moves 7.

## Answer

#### Problem
Three pegs A (source), B (auxiliary), C (destination); n disks on A, smallest on top. Move all to C, one disk at a time, only the top disk of a peg, and never a larger disk on a smaller one.

#### Recursive idea
TOH(n, from, to, aux): (1) TOH(n-1, from, aux, to); (2) move disk n from `from` to `to`; (3) TOH(n-1, aux, to, from). For n = 1 just move the disk.

#### Steps for 3 disks (1 smallest, 3 largest)
TOH(3,A,C,B) = TOH(2,A,B,C), move 3: A→C, TOH(2,B,C,A)
- TOH(2,A,B,C) = TOH(1,A,C,B) [1: A→C], 2: A→B, TOH(1,C,B,A) [3: C→B]
- TOH(2,B,C,A) = TOH(1,B,A,C) [5: B→A], 6: B→C, TOH(1,A,C,B) [7: A→C]

| Move | Disk | From | To | Pegs after the move (A / B / C) |
|---|---|---|---|---|
| 1 | 1 | A | C | 3,2 / - / 1 |
| 2 | 2 | A | B | 3 / 2 / 1 |
| 3 | 1 | C | B | 3 / 2,1 / - |
| 4 | 3 | A | C | - / 2,1 / 3 |
| 5 | 1 | B | A | 1 / 2 / 3 |
| 6 | 2 | B | C | 1 / - / 3,2 |
| 7 | 1 | A | C | - / - / 3,2,1 |

```text
Start   : A: 3 2 1 | B: - | C: -
Move 4  : A: -     | B: 2 1 | C: 3     (largest disk placed)
Finish  : A: -     | B: -   | C: 3 2 1
```
Total moves = 2³ − 1 = 7.

## Check yourself

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

1. In TOH(n, from, to, aux), what is the first recursive call?
   A. TOH(n-1, from, aux, to)
   B. TOH(n-1, from, to, aux)
   C. TOH(n-1, aux, to, from)
   D. TOH(n, from, aux, to)
   Answer: A. The first step moves n-1 disks from source to the auxiliary peg, using the destination as helper. (Key point: Recursive call structure)

2. In the 3-disk solution A to C, which move is the 4th?
   A. Disk 1 from B to A
   B. Disk 3 from A to C
   C. Disk 2 from A to B
   D. Disk 3 from A to B
   Answer: B. After the two smaller disks sit on B, the largest disk 3 moves A to C. (Key point: Move 4 for 3 disks)

3. How many moves does 3-disk TOH need?
   A. 8
   B. 6
   C. 7
   D. 9
   Answer: C. 2^3 - 1 = 7. (Key point: Total moves)

## Related in Data Structure and Algorithm

- [Tree recursion and TOH with n disks](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Atree-recursion-toh-algorithm) — Data Structure and Algorithm, chapter 5
- [TOH problem with solution for n disks](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Atoh-n-disks-solution) — Data Structure and Algorithm, chapter 5, asked 2×
- [TOH for 3 disks and recursion principle](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Atoh-3-disks-tree-principle) — Data Structure and Algorithm, chapter 5
- [TOH algorithm and recursion tree](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Atoh-algorithm-recursion-tree) — Data Structure and Algorithm, chapter 5, asked 2×
- [Recursion properties, Fibonacci, TOH algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Arecursion-properties-fibonacci-toh) — Data Structure and Algorithm, chapter 5
- [Recursion, Fibonacci and TOH](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Arecursion-fibonacci-toh) — Data Structure and Algorithm, chapter 5
