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?

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? Correct Answer S<sub>1</sub> is true and S<sub>2</sub> is true

Answer: Option 1

Explanation:

Statement 1:The sequence of procedure calls corresponds to a preorder traversal of the activation tree.

Consider following example 

Fun( int n )

{

 if( n==0 || n==1) 

  return n;

else {

return Fun(n/2) + Fun(n/2) ;

}

Suppose function call made as Fun(8). now recursion tree will be  

[ alt="F1 Raju.S 01-04-21 Savita D18" src="//storage.googleapis.com/tb-img/production/21/04/F1_Raju.S_01-04-21_Savita_D18.png" style="width: 480px; height: 222px;">

The Function call sequence will be (in terms of n): 8, 4, 2, 1, 1, 2, 1, 1, 4, 2, 1, 1, 2, 1, 1 ( Same as pre-order traversal of the tree )

The Function Returning Sequence will be : 1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8 ( Same as post-order traversal of the tree)

Hence This Statement is correct.

Statement 2:

This Statement is also correct.

Related Questions

The preorder traversal sequence of a binary search tree is 25, 15, 10, 4, 12, 22, 18, 24, 50, 35, 31, 44, 70, 66, 90 Which one of the following is the postorder traversal sequence of the same tree?
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?
Consider the following data and specify which one is Preorder Traversal Sequence, Inorder and Postorder sequences. S1: N, M, P, O, Q S2: N, P, Q, O, M S3: M, N, O, P, Q
Postorder traversal of a given binary search tree T produces following sequence of keys: 3, 5, 7, 9, 4, 17, 16, 20, 18, 15, 14 Which one of the following sequences of keys can be the result of an in-order traversal of the tree T?