Back to Academy
patterns
Recursion
Recursion solves problems by having a function call itself with a smaller input until it reaches a base case. Every recursive solution needs a base case to stop and a recursive case that breaks the problem down. Understanding the call stack and how each frame stores its own variables is key to mastering recursive thinking.
Use Cases
- •Tree and graph traversal algorithms
- •Mathematical computations like factorial and Fibonacci
- •Parsing nested structures like JSON or HTML
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(n) | O(n) | O(2^n) |
| Space | O(n) | ||
Visualization
Call:fact(5)
Implementation
Output
Click "Run Code" to see output...