Skip to content
Official PYQ · 2021

GATE CS 2021 Set 1 Q4 — Runtime Environments

Explain with AI

Consider the following statements.

  • S1:S_1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
  • S2:S_2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.

Which one of the following options is correct?

Choose one option
View worked solution

Answer: C

To understand the relationship between procedure execution and the activation tree, let us analyze how activations begin and end:

  • Activation Tree: A tree representation where each node corresponds to an activation of a procedure, and an edge from node AA to node BB exists if procedure AA calls procedure BB.

Statement S1S_1: Sequence of procedure calls

  • A procedure activation begins when it is called.
  • In any execution, a caller procedure must start its activation before it can call any callee procedures (its children in the activation tree).
  • Since a parent node is visited before its children, and children are called in left-to-right order, the sequence of procedure calls corresponds exactly to a preorder traversal of the activation tree. Thus, S1S_1 is true.

Statement S2S_2: Sequence of procedure returns

  • A procedure activation ends (returns) only after all the nested procedures it called (its children in the activation tree) have completed and returned.
  • Since a parent node is exited only after all its children have been fully processed and exited, the sequence of procedure returns corresponds exactly to a postorder traversal of the activation tree. Thus, S2S_2 is true.

Since both statements S1S_1 and S2S_2 are true, the correct option is C.

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

Published
Report a correction
Keep exploringMore Runtime Environments questions