Skip to content

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

Closed

Description

@justanothercoder-hub

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

Activity

  1. justanothercoder-hub commented on Jan 20, 2026

    @justanothercoder-hub
    Author

    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.

  2. justanothercoder-hub commented on Jan 22, 2026

    @justanothercoder-hub
    Author

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

  3. Harshit057 commented on Feb 6, 2026

    @Harshit057

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions