Which traversal is most suitable for deleting all nodes of a binary tree safely?

Options

  • A. Preorder
  • B. Inorder
  • C. Postorder
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. Postorder

Detailed Explanation

Postorder traversal is commonly used when deleting all nodes of a binary tree because it processes the children before processing their parent. Its order is Left → Right → Root. Thus, memory associated with child nodes can be released before the parent node. This principle is particularly useful in recursive tree deletion and helps avoid losing references to child subtrees before they are processed.