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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which is more memory-efficient: iteration or recursion?

A

Iteration (recursion uses extra space in the call stack).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the main disadvantage of recursion?

A

High memory usage (due to call stack).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly