Data Structures and Algorithms — Recursion
Recursion is a process where a function calls itself to solve a smaller instance of the problem. It's widely used in tree traversal, divide-and-conquer algorithms, and backtracking.
// Example: Factorial using recursion
function factorial(n) {
if (n === 0) return 1;
return n * factorial(n - 1);
}
console.log(factorial(5)); // Output: 120