I am trying to write recursive algorithms for the following string operations:
1) An algorithm to reverse a string.
2) An algorithm to test if two strings are equal to each other.
3) An algorithm to check if a string is a palindrome (for example, "eye" or "racecar") - reads the same forwards and backwards.
I am fairly new to writing algorithms, so even examples of procedures/similar methods would be appreciated.
Induction Steps: In each example, I'll show how to reduce the size of the problem by a little bit. You will need to do the base cases on your own.
To reverse "abcd", just take the last character "d" and stick it at the beginning of whatever the reverse of "abc" is.
To check if "abcd" equals "fbcd", just check that the last characters of each word ("d" and "d") match and that the remaining characters ("abc" and "fbc") match.
To check if "racecar" is a palindrome, just check that the first and last characters ("r" and "r") match and that the middle leftover part ("aceca") is a palindrome.