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.
- Host: GitHub
- URL: https://github.com/afa-farkhod/tower-of-hanoi
- Owner: afa-farkhod
- License: apache-2.0
- Created: 2023-04-06T06:46:43.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-01T09:25:48.000Z (almost 2 years ago)
- Last Synced: 2025-02-02T01:13:29.885Z (4 months ago)
- Topics: java, recursion, tower-of-hanoi
- Language: Java
- Homepage: https://en.wikipedia.org/wiki/Tower_of_Hanoi
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
![]()
- 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.
![]()
- Output of the implementation in the case of 4 disks example:
![]()