Tower of Hanoi Problem
The Tower of Hanoi is one of the best problems on Recursion. It is a Mathematical Puzzle solved by Recursion in the best way. This problem aims to Move n Number of discs from a source rod to a destination rod.
It consists of three rods and N number of Discs stacked in the First rod according to decreasing size,
Rules in Tower of Hanoi Problem
- Only one disc can be moved at a time.
- A bigger disc can't be placed on a smaller one.
- The disc should be stacked at the destination in the same manner as it was at the source position.
- Problem to be solved in the minimum number of steps.
Let us understand the Tower of Hanoi Problem with a Diagram.
The Minimum Number of Moves Required to solve the Tower of Hanoi Problem is 2n-1. where n is the total number of Discs.
Play Tower of Hanoi
I think Now You have understood this problem. Now Lets us proceed to solve the Tower of Hanoi problem in our Code.
Tower of Hanoi Problem can be solved in Two Ways:
- Using Recursion
- Using Stack
Tower of Hanoi Using Recursion
Tower of Hanoi Solution in C++
Tower of Hanoi Solution in C
Tower of Hanoi Solution in Java
Tower of Hanoi Solution in Python
Time Complexity of Tower of Hanoi Problem
-: Some of The Best Problems of Recursion:-
- Tower of Hanoi
- Print Permutation of String
- Print all subsets of a string
- Reverse a String using Recursion
- Factorial of a Large Number
- Print Palindrome of a number
- Shortest path in MATRIX.
- Print all possible words from phone digit
- Total path in a maze
- Implementation of Binary Tree