BCAC302
BCAC302
2023-24
Semester - 3rd
Year - 2nd
Session - 2024-25
Table of Content
1. Introduction..................................................1
2. History of the Tower of Hanoi......................2
3. Problem Definition.......................................3
4. Recursive Approach to Tower of Hanoi.........4
5. Mathematical Explanation............................5
6. Algorithm for Tower of Hanoi.......................6
7. Explanation of Code.....................................7
8. Time and Space Complexity.........................8
9. Applications of Tower of Hanoi....................9
10. Conclusion.............................................10-12
11. Bibliography...............................................13
12. Acknowledgment.........................................14
Introduction
The Tower of Hanoi is a well-known mathematical and computational puzzle
In the problem, there are three pegs and a number of disks of different sizes.
The objective is to move all the disks from the source peg to the destination
peg, using an auxiliary peg, under specific rules. The puzzle poses a challenge
because it seems simple at first glance, but as the number of disks increases,
steps to form a complete solution. This report will explore the Tower of
1
History of the Tower of Hanoi
far away, monks are tasked with transferring 64 golden disks from one
peg to another. The belief is that when the monks complete the task, the
Over time, the Tower of Hanoi has been used to teach programming
2
Problem Definition
In the Tower of Hanoi problem, the goal is to move n disks from
one rod (the source) to another rod (the destination) with the help of
an auxiliary rod. The rules for solving the problem are as follows:
simplicity of the rules contrasts sharply with the rapid increase in the
demonstrate recursion.
3
Recursive Approach to Tower of Hanoi
First, move n-1 disks from the source rod to the auxiliary rod
Then, move the largest disk directly from the source rod to the
destination rod.
Finally, move the n-1 disks from the auxiliary rod to the
4
Mathematical Explanation
This means that for each additional disk, the number of moves
large n.
5
Algorithm for Tower of Hanoi
The Tower of Hanoi algorithm is simple yet powerful. The recursive
following steps:
1. Move n-1 disks from the source rod to the auxiliary rod.
2. Move the nth disk (the largest) from the source rod to the
destination rod.
3. Move the n-1 disks from the auxiliary rod to the destination rod.
The steps are repeated until the base case is reached, which occurs
when only one disk remains. Here is the algorithm in general terms:
Steps:
1. Move n-1 disks from the source peg to the auxiliary peg.
2. Move the largest disk from the source peg to the destination
peg.
3. Move the n-1 disks from the auxiliary peg to the destination peg.
int main() {
int n;
printf("Enter the number of disks: ");
scanf("%d", &n);
towerOfHanoi(n, 'A', 'C', 'B');
return 0;
}
7
Time and Space Complexity
exponential time complexity means that for every additional disk, the
Time Complexity:
Space Complexity:
8
Applications of Tower of Hanoi
applications include:
Hanoi are applied in real-life scenarios, such as data storage and retrieval
4. Game Design: Many puzzles and video games incorporate the Tower of
9
Conclusion
10
Beyond its use in education, the Tower of Hanoi also finds practical
way, the Tower of Hanoi has transcended its role as a theoretical exercise and
exponential growth. The time complexity of the solution, O(2^n), reflects how
reminder that not all problems are efficiently solvable as their scale increases
In terms of algorithmic design, the Tower of Hanoi showcases the beauty and
Hanoi, are widely applicable in many areas of computer science, from sorting
11
In conclusion, the Tower of Hanoi is more than just an academic
principles, one can gain not only an appreciation for the elegance of
12
Bibliography
2009.
13
Acknowledgment
Thank you, Professor, for your mentorship and for helping me grow
14