What is recursion
Recursion is a technique in which a function calls itself to solve a problem by dividing it into smaller versions of the same…
Recursion is a powerful concept that allows you to solve problems by breaking them down into smaller parts and applying the same logic to each part. In this lesson, you will learn how to use recursion to tackle programming challenges in Python. Learn to employ recursive algorithms and assess their efficiency.
Recursion is a technique in which a function calls itself to solve a problem by dividing it into smaller versions of the same…
Writing a recursive function is easier if you always follow the same three steps. Do not try to follow all the calls in your…
Everything that is done with recursion can be done with a loop, and vice versa. So why use it? And, above all, when not to?
To write recursive functions without surprises you need to know what happens inside Python each time a function calls itself.
Besides simple recursion, there are three variants worth recognizing.
Create a Python program with a recursive function that calculates the result of raising an integer to the power of another…
Create a Python program with a recursive function called multiply() that receives two integers entered by the user and returns…
Create a Python program that uses recursion to calculate a number of the Fibonacci sequence. The sequence starts with the numbers…
Create a Python program with a recursive function that calculates the factorial of an integer entered by the user.
Create a Python program that asks the user for a text and uses a recursive function to reverse it.
Create a Python program with a recursive function that checks whether a text is a palindrome. A palindrome is a text that reads…
The Towers of Hanoi puzzle has three rods and n discs of different sizes stacked on the first one. They must be moved to the…
A sum of digits has a natural recursive definition: the sum of a number is its last digit plus the sum of the rest of the number.
Lists can contain other lists at any depth. A fixed loop does not work to go through them: recursion follows the shape of the…
Binary search splits a sorted list in half at each step, so it is another natural case for recursion: you search in one of the…
Computing b^e by multiplying e times is slow. Fast exponentiation takes advantage of the fact that b^e = (b^(e//2))^2 (× b if e…
In Pascal's triangle each row starts and ends with 1, and each middle number is the sum of the two above it in the previous row…
A staircase has n steps and you can climb 1, 2 or 3 steps at a time. In how many different ways can you climb it? It is a…