Interview Questions

You have given a node of a tree. that node is defined as below......

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

You have given a node of a tree. that node is defined as below......

Question:
You have given a node of a tree. that node is defined as below:
node(
int value,
node left;
node right;
node grandparent)

at the starting the grand parent node is null in the tree. you have to assign the grandparent node for all the nodes in the tree.


maybe an answer:


Every time you are calling postorder(root,gparent,count)
1. either gparent is null
2. or gparent->left=root or gparent->right=root
so , gparent is not the grand parent here , its parent .

One more thing , it will only set the gparent for the nodes where cout = 0 .
so , suppose we are at node current_node ,
then postorder(current_node->left,..) and postorder(current_node->right,..) will be called with count = 1 , and so the gparent for those nodes will not be assigned .

(Continued on next question...)

Other Interview Questions