Machine-translated by Google. Questions are authored in English.
Top

Discussion

The pre-order and post-order traversal of a binary tree generates the same output. The tree can have maximum :

  • A.Three nodes
  • B.Two nodes
  • C.One node
  • D.Any number of nodes

Answer: C

The tree can have at most one node.

Pre-order visits the root first and then its subtrees; post-order visits the subtrees first and the root last. In any tree with two or more nodes, the root is the first node of the pre-order output but the last node of the post-order output, so the two sequences differ.

Only a tree with a single node, where the root is both first and last, gives the same output in both traversals. So two nodes, three nodes and any number of nodes are all wrong.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.