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?
- A. Height 4, leaves 3
- B. Height 5, leaves 3
- C. Height 4, leaves 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.
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
- A rooted tree has 7 nodes with 1 child, 4 nodes with 2 children, 8 nodes with 3 children, 7 nodes with 4 children, and every other node is…
- DFS runs on the directed graph with adjacency lists A: BDE; B: E; C: AE; D: BF; E: –; F: BCG; G: –, starting at A, scanning lists in the…
- The weighted undirected graph A–E (19), A–F (20), B–F (2), C–D (25), C–E (10), C–F (7), D–E (18), D–F (8) has a unique MST. What is the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 91 nodes. How many leaves…
- What is the minimum number of edges m such that EVERY simple undirected graph with 13 vertices and m edges is guaranteed to be connected?
- Keys 51, 83, 75, 67, 42, 93, 22, 21, 38, 81 are inserted in order into an empty AVL tree. Counting a double rotation as two single…