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

Discussion

Which tree traversal visits root first, then left, then right ?

  • A.Inorder
  • B.Postorder
  • C.Level order
  • D.Preorder

Answer: D

Root first, then left, then right is preorder traversal.

The three depth-first traversals of a binary tree are named after where the root is visited. Preorder visits the root before its subtrees (root, left, right), inorder visits it between them (left, root, right), and postorder visits it after them (left, right, root).

Level order is breadth-first: it visits the nodes level by level from the top, left to right, using a queue, rather than following the root-left-right pattern.

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

Post your comment

Please log in or register to post a comment.