Given that retval = p → val + foo(p → left) + foo(p → right)
Means it will print the sum of ( value + leftsubtree whole value + right subtree whole value ).
Note that, until the child nodes completes the calculation, parent node calculation step will not complete.
Therefore leaf nodes returns the value of leaf nodes alone. ( 3 node, 8 node and 13 node will return 3, 8 and 13 respectively )
5 node will return 5+3+8 = 16
11 node will return 11+13 = 24
10 node will return 10+16+24 = 50
So sequence 3,8,16,13,24,50 only possible in the given options
As we know, there’s no rule about evaluation order of parameters of ‘+’
possible outcomes :
- 3,8,16,13,24,50
- 8,3,16,13,24,50
- 13,24,3,8,16,50
- 13,24,8,3,16,50