Which of the following statements are CORRECT? 1) Static allocation of all…

2014

Which of the following statements are CORRECT?

1) Static allocation of all data areas by a compiler makes it impossible to implement recursion.

2) Automatic garbage collection is essential to implement recursion.

3) Dynamic allocation of activation records is essential to implement recursion.

4) Both heap and stack are essential to implement recursion.

Answer: D. 1 and 3 onlyAnswer: statements 1 and 3 are correct. Statement 1: Static allocation of all data areas by a compiler makes it impossible to implement recursion.…

  1. A.

    1 and 2 only

  2. B.

    2 and 3 only

  3. C.

    3 and 4 only

  4. D.

    1 and 3 only

Attempted by 81 students.

Show answer & explanation

Correct answer: D

Answer: statements 1 and 3 are correct.

  • Statement 1: Static allocation of all data areas by a compiler makes it impossible to implement recursion.

    Explanation: General recursion requires that each function call gets its own activation record (local variables, return address, etc.). If all storage locations are fixed at compile time (no per-call allocation), you cannot create separate activation records for multiple simultaneous calls, so general recursion cannot be supported.

  • Statement 2: Automatic garbage collection is essential to implement recursion.

    Explanation: This is false. Recursion is typically implemented by allocating activation records on a runtime stack, which is managed deterministically (push on call, pop on return). Garbage collection of heap objects is not required for recursion.

  • Statement 3: Dynamic allocation of activation records is essential to implement recursion.

    Explanation: This is true. Each recursive call needs its own activation record created at runtime so that local state and return information are kept separate. Allocating these records dynamically at call time (commonly on a growing/shrinking call stack) is essential.

  • Statement 4: Both heap and stack are essential to implement recursion.

    Explanation: This is false. A stack (or some stack-like mechanism) is essential to hold activation records, but the heap is not required for recursion. Some implementations could place activation records on the heap, but the heap itself is not universally necessary.

Conclusion: Statements 1 and 3 correctly describe requirements/constraints related to recursion; statements 2 and 4 are incorrect.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…