Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] Adding "TOWER OF HANOI" to Recursion File

Open justanothercoder-hub opened this issue 10 months ago • 4 comments

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

Image

justanothercoder-hub avatar Jan 20 '26 08:01 justanothercoder-hub

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 avatar Jan 20 '26 08:01 justanothercoder-hub

I have opened a Pull Request to solve this: #7228

justanothercoder-hub avatar Jan 22 '26 11:01 justanothercoder-hub

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

DenizAltunkapan avatar Feb 02 '26 19:02 DenizAltunkapan

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:

  1. Writing a minimal, clear recursive solution
  2. Adding concise docs explaining the recursion flow
  3. Including unit tests for correctness
  4. 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.

Harshit057 avatar Feb 06 '26 05:02 Harshit057