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

Discussion

The set T represents various traversals over binary tree. The set S represents the order of visiting nodes during a traversal.

TS
I: InorderL: left subtree, node, right subtree
II: PreorderM: node, left subtree, right subtree
III: PostorderN: left subtree, right subtree, node

Which one of the following is the correct match from T to S ?

  • A.I - L, II - M, III - N
  • B.I - M, II - L, III - N
  • C.I - N, II - M, III - L
  • D.I - L, II - N, III - M

Answer: A

The correct match is I - L, II - M, III - N.

The names say where the node is visited relative to its subtrees:

  • Inorder: left subtree, node, right subtree (L). For a binary search tree this lists the keys in sorted order.
  • Preorder: node first, then left and right subtrees (M).
  • Postorder: left and right subtrees first, node last (N).

Every other option assigns at least one traversal the wrong position for the node: matching inorder to 'node, left, right' or postorder to 'left, node, right' confuses the prefixes pre, in and post, which refer exactly to that position.

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

Post your comment

Please log in or register to post a comment.