Traverse the following tree in postorder a c d g r f a d c g
Traverse the following tree in postorder a c d g r f a d c g r f a d c r g f a d r c g f What is a possible output of the following code? 1 2 1 0 0 0 1 2 1 1 1 1
Solution
In postorder we traverse tree in below order:
Left right parent
So for the parent f we will first traverse left child and then right child
For c we will first traverse left and then right so the output of tree rooted at c is
a d c
similarly for g the output is
r g
Then for the f is
a d c r g f
So the correct option is C.
8)
random()%2 will generate number between 0 to 1
hence random()%2+2 will generate number between 2 to 3
So the current output can have 2 or 3 numbers
seeing the printf statement it will only generate number in 0 to 1 range
since we do not have an option in which output size is 2 and the only numbers 0 and 1
correct option is B which is 1 0 0
