An open API service indexing awesome lists of open source software.

https://github.com/afa-farkhod/tower-of-hanoi

Tower Of Hanoi Problem is solved in java using the recursion.
https://github.com/afa-farkhod/tower-of-hanoi

java recursion tower-of-hanoi

Last synced: 2 months ago
JSON representation

Tower Of Hanoi Problem is solved in java using the recursion.

Awesome Lists containing this project

README

        

# [Tower-Of-Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi)
Tower Of Hanoi Problem is solved in java using the recursion.

- The Tower of Hanoi problem is a classic problem that can be solved easily usingrecursion, but it is difficult to solve otherwise.
- The problem involves moving a specified number of disks of distinct sizes from one tower to another while observing the following rules:
- There are n disks labeled 1, 2, 3, . . . , n and three towers labeled A, B, and C.
- No disk can be on top of a smaller disk at any time.
- All the disks are initially placed on tower A.
- Only one disk can be moved at a time, and it must be the smallest disk on a tower.

- The objective of the problem is to move all the disks from A to B with the assistance of C. For example, if you have three disks, the steps to move all of the disks from A to B are shown in the figure


Image

- Analyze the Tower of Hanoi Problem.

- The Tower of Hanoi problem recursively moves n disks from tower A to tower B with the assistance of tower C as following:
- Move the first n-1 disks from A to C with the assistance of tower B
- Move disk n from A to B
- Move n-1 disks from C to B with the assistance of tower A

- The complexity of the algorithm is measured by the number of moves. Let T(n) denote the number of moves for the algorithm to move n disks from tower A to tower B with T(1)=1.


Image

- Output of the implementation in the case of 4 disks example:


Image