Analyzing a Recursive Algorithm
A good example of using recursion is determining whether a word is a palindrome (the same backwards and forwards). Is the word redivider a palindrome? To answer this question, you’ll probably look at the first and last letter to see if they’re the same, then mentally ignore them and look at the remaining part, seeing that the new first and last letter es match, and so on, until you get to the v in the middle, and then you’ll conclude that the word is a palindrome.
Now this word: runner. Again, you can see that the beginning and ending letters are the same, ignore them, and then stop as soon as you see that the u and e don’t match—there’s no need to proceed further.
Here’s a pseudocode representation of your ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access