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?
- A. Height 5, leaves 4
- B. Height 4, leaves 5
- C. Height 3, leaves 3
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- The POSTORDER traversal of a BST with distinct keys is 16, 27, 31, 56, 95, 79, 58, 51, 45, 32. What are the height of the tree (edges on…
- A tree on vertices 1–11 has edges 2–1, 3–2, 4–3, 5–2, 6–3, 7–5, 8–7, 9–6, 10–9, 11–9. What is the size of a maximum independent set (no…
- Edit distance between BINARY and GRAPHICAL where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- Keys 37, 84, 56, 34, 79, 18, 83, 69, 74 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- All suffixes of the string 'abab' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- How many subsets of {3, 5, 6, 7, 8, 10, 14} have sum exactly 24?