Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited `in a postorder, inorder and preorder traversal respectively, of a complete binary tree. Which of the following is always true?
@vishalsharma539
I do not understand what is the meaning of Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited `in a postorder, inorder and preorder traversal respectively??
@Lakshman Patel RJIT
It is nothing but just simple preorder, postorder, inorder traversal.
Inorder : Left $\rightarrow$ Root $\rightarrow$ Right Preorder : Root $\rightarrow$ Left $\rightarrow$ Right Postorder: Left $\rightarrow$ Right $\rightarrow$ Root If the binary tree is full (last level is fully filled), the last visited node in Inorder and Preorder must be the rightmost one in the last level. But for a complete binary tree this need not be the case (in a complete binary tree last level need not be fully filled) and LASTPRE will be from the second last level in case the complete binary tree is not full. So, choice (D).
@Abhisek Tiwari Will it 'B' for full binary Tree?
@Abhisek Tiwari
Will it 'B' for full binary Tree?
Yes, absolutely why it can’t be...
because every time you make the inorder and preorder traversal you will get the …
LASTIN = LASTPRE
@Gate Keeda I think that depends. E.g. if you take this complete binary tree, then you'll get both LASTIN and LASTPRE as 7. So taking an examples is probably not the best way to address this question.
@Arjun sir, I believe you mean to say LASTIN will be from second last level.As in that case LASTPRE will from last and LASTIN from second last.
Here, you have to be careful. It Says, "Complete binary tree" for which every level except last is completely filled and at last level, nodes are as far as left possible.
REVERSE APPROACH !!
Consider a Complete Binary Tree with only 1 node, say A,
Then its PREORDER = POSTORDER = INORDER = A
Therefore, only Option D matches (as Question ask, which always TRUE)
counter example for option B.
64.3k questions
77.9k answers
244k comments
80.0k users