Recursive
Recursive
solve a problem. It is particularly useful for problems that can be broken down into smaller, similar
subproblems. Here are some key points and applications of recursion:
1. Base Case: The condition under which the recursion ends. Without a base case, the function
would call itself indefinitely, leading to a stack overflow.
2. Recursive Case: The part of the function where it calls itself with a modified argument, moving
towards the base case.
Applications of Recursion
1. Mathematical Computations:
2. Data Structures:
Merge Sort: Divides the array into halves, recursively sorts them, and then merges the
sorted halves.
Quick Sort: Divides the array into partitions and recursively sorts the partitions.
4. Dynamic Programming:
Memoization: Storing the results of expensive function calls and reusing them when the
same inputs occur again.
Recursive Solutions: Many dynamic programming problems are solved using recursion
with memoization.
5. Backtracking:
N-Queens Problem: Placing N queens on an N×N chessboard such that no two queens
threaten each other.
Sudoku Solver: Filling the Sudoku grid by trying out possible numbers and backtracking
when a conflict is found.
Example: Factorial Calculation