Page 551 - Computer science 868 Class 12
P. 551
Ans. void addNode
(Node ptr, double ss)
{
Node s=new Node( );
s.sal = ss;
s.next=null;
for(Node t=ptr; t.next!=null; t=t.next);
t.next=s;
}
(ii) Answer the following questions from the diagram of a Binary Tree given below: [ISC 2023]
A
F B
D G H
E
(a) Write the pre-order traversal of the above tree structure.
Ans. Pre-order traversal of the above tree structure is A F D G B H E
(b) Name the parent of the nodes D and B.
Ans. The parent of the nodes D and B are F and A
(c) State the level of nodes E and F when the root is at level 0.
Ans. Level of E = 3 and level of F =1
5. Answer the following questions from the diagram of a Binary Tree given below:
A
B C
D E F
G H I
(i) State the siblings of the nodes C and E. Also, state the predecessor node(s) and successor node(s) of node B. [ISC 2022]
Ans. Siblings of C : B
Siblings of E : D
Predecessor of B : A
Successor of B : D and E
(ii) Write the in-order traversal of the left sub tree and the pre-order traversal of the right sub-tree [ISC 2022]
Ans. IN-ORDER TRAVERSAL: DBGE
PRE-ORDER TRAVERSAL: CFHI
6. Convert the following infix notation to prefix notation: P* (Q-R) +S [ISC 2022]
Ans. Steps of Conversion:
Adding brackets on both ends (P*(Q-R)+S)
Reversing the expression (S+(R-Q)*P)
Infix to postfix SRQ-P*+
Reversing the postfix expression +*P-QRS
Ans. +*P-QRS
549
Data Structures 549

