Add recursive palindrome check and Tower of Hanoi#24
Open
Bushra453 wants to merge 1 commit intomuskankhedia:mainfrom
Open
Add recursive palindrome check and Tower of Hanoi#24Bushra453 wants to merge 1 commit intomuskankhedia:mainfrom
Bushra453 wants to merge 1 commit intomuskankhedia:mainfrom
Conversation
Implemented recursive functions for palindrome check and Tower of Hanoi solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.