The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the postorder traversal of the tree ?
(A) 10, 11, 12, 15, 16, 18, 19, 20
(B) 11, 12, 10, 16, 19, 18, 20, 15
(C) 20, 19, 18, 16, 15, 12, 11, 10
(D) 19, 16, 18, 20, 11, 12, 10, 15

Respuesta :

Answer:

The answer is (B) 11, 12, 10, 16, 19, 18, 20, 15

Step-by-step explanation:

In a preorder traversal of a binary search tree (BST), we visit the root node, then the left subtree, and finally the right subtree.

In this case, the preorder traversal is 15 (root), 10 (left child), 12, 11 (left child of 10), 20 (right child of 15), 18 (left child of 20), 16 (left child of 18), 19 (right child of 18).

Understanding Postorder Traversal:

In postorder traversal, we visit the left subtree, then the right subtree, and finally the root node.

Reconstructing the Tree:

We know 15 is the root because it appears first in preorder.

Since 10 appears before 12 in preorder and 15 is the root, 10 is the left child of 15.

Similarly, 20 is the right child of 15 due to its position in preorder.

Following the same logic, 11 is the left child of 10 and 18 is the left child of 20.

Finally, 16 and 19 are children of 18, with 16 being the left child and 19 the right child based on their order in the preorder sequence.

Postorder Traversal:

Now that we understand the tree structure, the postorder traversal becomes clear:

Visit all nodes in the left subtree completely (11, 12, 10).

Visit all nodes in the right subtree completely (16, 19, 18).

Finally, visit the root node (15).

Q&A Education