Data Structures & AlgorithmsHardProduct-company placement
A binary search tree holds exactly the keys 17, 22, 27, 39, 40, 92, 97, 98. Which ONE of the following can be its POSTORDER traversal?
- A. 22, 17, 27, 39, 98, 40, 92, 97
- B. 22, 17, 27, 39, 92, 40, 98, 97
- C. 39, 17, 27, 22, 92, 40, 98, 97
- D. 22, 17, 27, 39, 92, 98, 40, 97
Correct answer: B. 22, 17, 27, 39, 92, 40, 98, 97
The last key is the root; the keys before it must split into a block of smaller keys followed by a block of larger keys, recursively. Only 22, 17, 27, 39, 92, 40, 98, 97 splits correctly at every level.
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 BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 58?
- What is the length of the longest common subsequence of MATRIX and MARTIAN, and how many DISTINCT longest common subsequences (as strings)…
- Lectures occupy half-open intervals [start, end): [3, 10), [6, 10), [7, 12), [9, 11), [10, 15), [10, 17), [10, 18), [20, 25). A lecture…
- A binary max-heap is stored in a 0-indexed array [57, 47, 54, 14, 15, 6, 21]. Perform, in order: delete-max, insert 10, delete-max, insert…
- Keys 13, 30, 35, 39, 54 are searched with frequencies 8, 1, 9, 9, 12 respectively (only successful searches). The cost of a BST is Σ…
- A min-heap holds 63 distinct keys in a 0-indexed array (a full tree with 6 levels). At how many different indices can the 5th-smallest key…