Data Structures & AlgorithmsHardGATE CS · Product-company placement

The POSTORDER traversal of a BST with distinct keys is 17, 16, 34, 44, 51, 66, 59, 85, 93, 46. What are the height of the tree (edges on the longest root-to-leaf path) and its number of leaves?

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

Correct answer: A. Height 4, leaves 3

The last key 46 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 46, 44, 93, 34, 85, 16, 59, 17, 51, 66: height 4, 3 leaves.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic