Questions: Tree Traversals

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You need to delete all nodes in a binary tree, freeing memory in an order that ensures children are always deleted before their parent. Which traversal should you use?

APreorder (root, left, right) — visit parent first, then children
BInorder (left, root, right) — balanced between parent and children
CPostorder (left, right, root) — visit both subtrees before the parent
DLevel-order — process nodes top to bottom by level
Question 2 Multiple Choice

You perform an inorder traversal on a binary tree and get the sequence: 15, 7, 22, 3, 11. What can you conclude?

ANothing — inorder traversal of an arbitrary binary tree tells you nothing about whether it is a BST
BThe tree is a valid BST, because inorder traversal always produces sorted output
CThe tree is not a valid BST, because the output is not in sorted order
DYou need to also check the preorder output before drawing any conclusion
Question 3 True / False

Inorder traversal of any binary tree produces elements in sorted order.

TTrue
FFalse
Question 4 True / False

Preorder traversal visits a parent node before its children, which makes it naturally suited for copying a tree or producing a top-down representation of its structure.

TTrue
FFalse
Question 5 Short Answer

What determines which depth-first traversal (preorder, inorder, or postorder) to use, and why does the order matter?

Think about your answer, then reveal below.