Question
Consider the following statements.
: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2021 answer key
Solution
Connect procedure call entry and exit events to tree traversal orders on an activation tree.
In a compiler's runtime environment, an activation tree models procedural execution where each node represents an execution of a procedure. A procedure calls its children, and control enters a node before entering any of its children.
Therefore, the sequence of procedure calls visits the parent before its children, which corresponds precisely to a preorder traversal of the activation tree. Hence is true.
A procedure cannot return until all procedures called by it (its children) have returned. Thus, control exits a node only after all its children have finished, which corresponds precisely to a postorder traversal of the activation tree. Hence is true.
Since both and are true, option C is correct.
C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology (CS, Set-1)
- Question
- 14 of 65, printed as CS Q.4
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.