<aside> <img src="/icons/table_red.svg" alt="/icons/table_red.svg" width="40px" /> Table of Contents
</aside>
<aside> 💡
<aside> 💡
<aside> 💡
<aside> 💡
Recursion is a fundamental concept in computer science, providing an elegant way to solve problems by dividing them into smaller, more manageable subproblems. It involves a function calling itself directly or indirectly.
Definition
Characteristics of Recursion
How Recursion Works
Simple Example
Factorial Calculation Using Recursion: The factorial of $n$ is defined as:
$$ n! = n \times (n-1)! $$
Code:
def factorial(n):
if n == 0 or n == 1: # Base case
return 1
else:
return n * factorial(n - 1) # Recursive case
print(factorial(5)) # Output: 120
Applications of Recursion