Data Structures & AlgorithmsHardGATE CS · Product-company placement

The POSTORDER traversal of a BST with distinct keys is 11, 32, 67, 77, 91, 95, 94, 92, 80, 52. What are the height of the tree (edges on the longest root-to-leaf path) and its number of leaves?

  1. A. Height 5, leaves 4
  2. B. Height 4, leaves 5
  3. C. Height 3, leaves 3
  4. D. Height 4, leaves 4

Correct answer: D. Height 4, leaves 4

The last key 52 is the root; split the rest into smaller and larger blocks and recurse (or insert the reversed postorder into a BST). The rebuilt tree has level order 52, 32, 80, 11, 77, 92, 67, 91, 94, 95: height 4, 4 leaves.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic