Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q18 — Runtime Environments

Explain with AI

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. 
Choose one option
View worked solution

Answer: D

To determine which statements are correct, let us analyze each of them individually:

  • Statement 1: "Static allocation of all data areas by a compiler makes it impossible to implement recursion."
    Correct. In static allocation, memory for all variables and activation records is allocated at compile time. This means there is exactly one fixed memory location for each function's local variables. Since recursion requires multiple active instances of the same function to exist simultaneously (each with its own set of local variables and parameters), static allocation cannot support recursion.

  • Statement 2: "Automatic garbage collection is essential to implement recursion."
    Incorrect. Automatic garbage collection is a mechanism to reclaim unused heap memory. Recursion is typically managed using a stack-based runtime environment where activation records are automatically deallocated when a function returns. No garbage collection is needed for this.

  • Statement 3: "Dynamic allocation of activation records is essential to implement recursion."
    Correct. Because the depth of recursion is determined at runtime, activation records must be allocated dynamically (typically pushed onto a runtime stack) as recursive calls are made, and deallocated (popped) when they return.

  • Statement 4: "Both heap and stack are essential to implement recursion."
    Incorrect. Only a stack (or dynamic allocation of activation records) is essential to manage the nested function calls. A heap is not required to implement recursion.

Thus, only statements 1 and 3 are correct.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Runtime Environments questions