• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 31, 2024 |65.1K Views

Tower of Hanoi

Description
Discussion

Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

Only one disk can be moved at a time.
Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
No disk may be placed on top of a smaller disk.
Approach :

Let rod 1 = 'A', rod 2 = 'B', rod 3 = 'C'.
An example with 2 disks :
Step 1 : Shift first disk from 'A' to 'B'.

Tower of Hanoi  : https://www.geeksforgeeks.org/c-program-for-tower-of-hanoi/