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?
View worked solution
Answer: D
To determine which of the relations is always true for a complete binary tree, we can analyze small counterexamples.
Recall the definitions of the traversals:
- Preorder: Root Left Right
- Inorder: Left Root Right
- Postorder: Left Right Root
Counterexample 1: Complete Binary Tree with 2 nodes ()
A
/
B
- Preorder:
- Inorder:
- Postorder:
Here, (since ). This disproves Option B.
Counterexample 2: Complete Binary Tree with 3 nodes ()
A
/ \
B C
- Preorder:
- Inorder:
- Postorder:
Here:
- (since ). This disproves Option A.
- (since ). This disproves Option C.
Since none of the statements in A, B, or C are always true, the correct choice is D.
Free practice · Your answers on this page are not saved.
