Determining if a string is a Palindrome using recursion
Below is an example of how to determine if a word is a palindrome using recursion. A Palindrome is a string that could be read the same way in either direction such as racecar, mom, and even a. This tutorial expects you to understands the following.
Example of finding if a word is a palindrome
To determine if a word is a palindrome do the following.
- Compare the first and last character
- If these characters are the same, disregard these characters and repeat until one one character or no characters remain
Example:
// Check first and last character
[ r ] [ a ] [ c ] [ e ] [ c ] [ a ] [ r ]// Second iteration
[ a ] [ c ] [ e ] [ c ] [ a ]// Third iteration
[ c ] [ e ] [ c ]// Fourth iteration
[ e ]// The word is a palindrome.
Now let’s try one that isn’t a palindrome.
// First iteration
[ t ] [ a ] [ b ] [ t ]// In our second iteration, a and b don’t match
[ a ] [ b ]






