in Compiler Design retagged by
6,533 views
9 votes
9 votes

Consider the following statements.

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

Which one of the following options is correct?

  1. $S_1$ is true and $S_2$ is false
  2. $S_1$ is false and $S_2$ is true
  3. $S_1$ is true and $S_2$ is true
  4. $S_1$ is false and $S_2$ is false
in Compiler Design retagged by
by
6.5k views

4 Comments

Option C, both are true?
1
1

These statements are directly copied from Aho-ullman book page no 432. see here

3
3
Compiler Principles Techniques & Tools – by – Aho, Lam. Sethi & Ullman

 

0
0

3 Answers

15 votes
15 votes
Best answer

Correct Answer: C


$S_1$: Is true because to perform procedure calls, first parent function will call child functions  and hence it resembles preorder.

$S_2$: Is true because to return parent function ,  we must return child functions first. Hence it resembles post order.

selected by

2 Comments

These statements are directly copied from Aho-ullman book page no 432. see here

7
7
calling sequence of activation   record is always in preorder traversal while return is always postorder.
0
0
11 votes
11 votes
Option C :- Both S1 and S2 are true.
Consider the recursion tree :-  
                  fun(A)                           Procedure Calls :- A → B → C → D → E   : Preorder
                //        \\                           Return :-               C → D → B → E → A    :Postorder
            fun(B)    fun(E)
           //     \\
     fun(C)   fun(D)
2 votes
2 votes
when we call a procedure, it goes to the stack

and as we know stack uses both pre-order and post-order traversal

Both statements are correct :)
edited by
Answer:

Related questions