Skip to content
Official PYQ · 2000

GATE CS 2000 Q2.16 — Trees

Explain with AI

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?

Choose one option
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 →\rightarrow Left →\rightarrow Right
  • Inorder: Left →\rightarrow Root →\rightarrow Right
  • Postorder: Left →\rightarrow Right →\rightarrow Root

Counterexample 1: Complete Binary Tree with 2 nodes (N=2N = 2)

    A
   /
  B
  • Preorder: A,B  ⟹  LASTPRE=BA, B \implies \text{LASTPRE} = B
  • Inorder: B,A  ⟹  LASTIN=AB, A \implies \text{LASTIN} = A
  • Postorder: B,A  ⟹  LASTPOST=AB, A \implies \text{LASTPOST} = A

Here, LASTIN≠LASTPRE\text{LASTIN} \neq \text{LASTPRE} (since A≠BA \neq B). This disproves Option B.


Counterexample 2: Complete Binary Tree with 3 nodes (N=3N = 3)

    A
   / \
  B   C
  • Preorder: A,B,C  ⟹  LASTPRE=CA, B, C \implies \text{LASTPRE} = C
  • Inorder: B,A,C  ⟹  LASTIN=CB, A, C \implies \text{LASTIN} = C
  • Postorder: B,C,A  ⟹  LASTPOST=AB, C, A \implies \text{LASTPOST} = A

Here:

  • LASTIN≠LASTPOST\text{LASTIN} \neq \text{LASTPOST} (since C≠AC \neq A). This disproves Option A.
  • LASTPRE≠LASTPOST\text{LASTPRE} \neq \text{LASTPOST} (since C≠AC \neq A). 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.

Published
Report a correction
Keep exploringMore Trees questions