retagged by
6,616 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
retagged by

3 Answers

Best answer
15 votes
15 votes

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
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

8 votes
8 votes
4 answers
1
Arjun asked Feb 18, 2021
8,929 views
Let the representation of a number in base $3$ be $210$. What is the hexadecimal representation of the number?$15$$21$$\text{D}2$$528$
9 votes
9 votes
1 answer
3
Arjun asked Feb 18, 2021
2,623 views
A circular sheet of paper is folded along the lines in the directions shown. The paper, after being punched in the final folded state as shown and unfolded in the reverse...
16 votes
16 votes
1 answer
4
Arjun asked Feb 18, 2021
9,083 views
​​​​​​The ratio of boys to girls in a class is $7$ to $3$.Among the options below, an acceptable value for the total number of students in the class is:$21$$3...