Skip to content

Add recursive palindrome check and Tower of Hanoi#24

Open
Bushra453 wants to merge 1 commit intomuskankhedia:mainfrom
Bushra453:main
Open

Add recursive palindrome check and Tower of Hanoi#24
Bushra453 wants to merge 1 commit intomuskankhedia:mainfrom
Bushra453:main

Conversation

@Bushra453
Copy link

Implement Recursive Palindrome Check and Tower of Hanoi Algorithm

Description

This pull request implements the missing recursive functions in the recursion_algorithms module.

Changes Made

Implemented is_palindrome_recursive() using recursion to check whether a string is a palindrome.

Implemented tower_of_hanoi() to solve the Tower of Hanoi problem recursively and return the list of moves.

Added proper base cases and recursive calls for both algorithms.

Ensured the functions match the provided docstring examples and expected outputs.

Details

Palindrome Recursive Function

Checks if the first and last characters of the string are the same.

Recursively checks the remaining substring.

Base case: string length ≤ 1.

Tower of Hanoi

Moves n-1 disks from source to auxiliary rod.

Moves the largest disk to the destination rod.

Moves n-1 disks from auxiliary to destination rod.

Example Outputs
is_palindrome_recursive("racecar")

True

tower_of_hanoi(2, 'A', 'C', 'B')

['Move disk 1 from A to B',

'Move disk 2 from A to C',

'Move disk 1 from B to C']

Testing

Verified outputs using the examples provided in the docstrings.

Confirmed recursive logic works correctly for different inputs.

Implemented recursive functions for palindrome check and Tower of Hanoi solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant