Consider the following statements. S1: The sequence of procedure calls…
2021
Consider the following statements.
S1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
Answer: C. S1 is true and S2 is true — S1: "The sequence of procedure calls corresponds to a preorder traversal."TRUE Reason: When a function/procedure is called: We first visit the procedure…
- A.
S1 is true and S2 is false
- B.
S1 is false and S2 is true
- C.
S1 is true and S2 is true
- D.
S1 is false and S2 is false
Attempted by 292 students.
Show answer & explanation
Correct answer: C
S1: "The sequence of procedure calls corresponds to a preorder traversal."
TRUE
Reason:
When a function/procedure is called:
We first visit the procedure (root)
Then recursively call its children
This is exactly how Preorder traversal works:
Preorder = Root → Left → Right
So, procedure calls = preorder traversal.
S2: "The sequence of procedure returns corresponds to a postorder traversal."
TRUE
Reason:
A procedure returns only after:
All its child procedures have finished
Then it returns to the caller
This is exactly the Postorder traversal behavior:
Postorder = Left → Right → Root
So procedure returns = postorder traversal.
A video solution is available for this question — log in and enroll to watch it.
Explore the full course: Iocl Engineers Officers Grade A Paper 2