https://cs.slides.com/colt_steele/searching-algorithms-22

Understanding Recursion: The Tale of Martin and the Dragon

Recursion is a programming concept where a function calls itself to solve smaller instances of the same problem until it reaches a base case. Here's an illustrative story:

The Story of Martin and the Dragon

Once upon a time, there was a boy named Martin who lived in a world of wizards and alchemists. Martin was an apprentice wizard in training.

One day, Martin's master gave him a task: "Go to the dragon's cave with this list of numbers and find out if any of them are odd."

When Martin reached the cave, he found an irritable dragon who refused to check the entire list.

"I'll only tell you if the FIRST number in your list is odd. That's all," growled the dragon.

Martin thought carefully and came up with a clever solution:

Martin smiled triumphantly. "Since none of the first numbers were odd, and I've checked every number by making it the first number in a smaller list, I can conclude that NONE of the numbers in my original list are odd!"

The dragon nodded. "Congratulations, boy. You've discovered recursion."

What is Recursion?

Recursion is solving a problem by: