You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE REQUEST] Adding "TOWER OF HANOI" to Recursion File #7223
I would like to add the problem "Tower of Hanoi" to recursion file. I think its a great beginner application of the recursion concept.
Issue details
The Core Rules
1.Only one disk can be moved at a time.
2.A disk can only be moved if it is the uppermost disk on a stack.
3.No larger disk may be placed on top of a smaller disk.
The Stepped Algorithm (Recursive)
To move $3$ disks from a Source peg to a Destination peg using an Auxiliary (helper) peg, follow these three logical steps:
Step 1: Move the top $3-1$ disks from the Source peg to the Auxiliary peg. (This clears the path for the largest disk).
Step 2: Move the remaining largest disk directly from the Source peg to the Destination peg
.Step 3: Move the $3-1$ disks that were sitting on the Auxiliary peg to the Destination peg. (Placing them on top of the largest disk).
Hi! I am a first-year B.Tech CSE student. I would like to work on this issue. I plan to implement the Tower of Hanoi in the com.thealgorithms.recursion package. I've already set up the project locally with Java 25 and Maven 3.9.12.
You’re right — there’s already a TowerOfHanoi implementation under com.thealgorithms.puzzlesandgames.
That said, I think a recursion-focused version under com.thealgorithms.recursion could still be useful, since this problem is commonly taught as a core recursion example rather than a puzzle.
I can keep it non-duplicative by:
Writing a minimal, clear recursive solution
Adding concise docs explaining the recursion flow
Including unit tests for correctness
Referencing the existing implementation in Javadoc
Happy to update the PR this way, or close it if you feel it’s redundant. Let me know what you prefer.
Activity
justanothercoder-hub commentedon Jan 20, 2026
Hi! I am a first-year B.Tech CSE student. I would like to work on this issue. I plan to implement the Tower of Hanoi in the com.thealgorithms.recursion package. I've already set up the project locally with Java 25 and Maven 3.9.12.
justanothercoder-hub commentedon Jan 22, 2026
I have opened a Pull Request to solve this: #7228
DenizAltunkapan commentedon Feb 2, 2026
it seems like this already exists in https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/puzzlesandgames/TowerOfHanoi.java, right? @justanothercoder-hub
Harshit057 commentedon Feb 6, 2026
You’re right — there’s already a TowerOfHanoi implementation under com.thealgorithms.puzzlesandgames.
That said, I think a recursion-focused version under com.thealgorithms.recursion could still be useful, since this problem is commonly taught as a core recursion example rather than a puzzle.
I can keep it non-duplicative by:
Happy to update the PR this way, or close it if you feel it’s redundant. Let me know what you prefer.