Iteration vs Recursion Flashcards
1
Q
What is the main difference between iteration and recursion?
A
Iteration uses loops (for / while), while recursion calls itself with a base case.
2
Q
Which is more memory-efficient: iteration or recursion?
A
Iteration (recursion uses extra space in the call stack).
3
Q
What is the main disadvantage of recursion?
A
High memory usage (due to call stack).
4
Q
What is the best way to convert recursion to iteration?
A
Use an explicit stack (for DFS-like problems) or loop with accumulators (for tail-recursion cases).