Difficulty: Easy
Correct Answer: Yes
Explanation:
Introduction / Context:
Choosing between recursion and iteration affects performance and memory. While recursion can produce elegant code and is essential for certain problems (for example, divide-and-conquer), it typically incurs function-call overhead and consumes stack frames. This question asks about the usual, practical performance comparison in C.
Given Data / Assumptions:
Concept / Approach:
Each recursive call generally pushes a new frame (return address, saved registers, locals) and performs a call/return sequence. Iterative loops avoid repeated call overhead by reusing a single frame. Unless a compiler applies tail-call elimination or inlining, the recursive version often runs slower and uses more stack.
Step-by-Step Solution:
Verification / Alternative check:
Benchmark factorial or Fibonacci (memoized vs. iterative). Iterative versions typically outperform naive recursion in C.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming tail-call optimization will always occur; forgetting stack limits and the risk of deep recursion.
Final Answer:
Yes.
Discussion & Comments