[FEATURE REQUEST] Adding "TOWER OF HANOI" to Recursion File
What would you like to Propose?
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).
Additional Information
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.
I have opened a Pull Request to solve this: #7228
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
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.