Data Structures & AlgorithmsModerateProduct-company MCQ pattern
Seven distinct keys are stored in a max-heap in a 0-indexed array. Which statement is correct?
- A. The smallest key is always at index 6
- B. The second largest key can be at any index from 1 to 6
- C. The smallest key can be at any index from 1 to 6
- D. The smallest key can only be at index 3, 4, 5 or 6, and the second largest only at index 1 or 2
Correct answer: D. The smallest key can only be at index 3, 4, 5 or 6, and the second largest only at index 1 or 2
The minimum cannot have a child (its child would have to be smaller), so it is one of the 4 leaves, indices 3–6, not necessarily the last one. The second largest has only the root above it, so it must be a child of the root: index 1 or 2.
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
- How many of these statements are correct? (i) Building a heap from n elements by bottom-up sift-down takes O(n) time. (ii) Inserting n…
- How many different max-heaps (as arrays) can be formed from 5 distinct keys?
- Keys 50, 30, 70, 20, 40, 60, 80, 65 are inserted into an empty BST, then 50 is deleted by replacing it with its inorder SUCCESSOR. What is…
- How many of the 7! insertion orders of the keys 1–7 produce the perfectly balanced BST with root 4, children 2 and 6, and leaves 1, 3, 5, 7?
- A binary tree has inorder 9 5 1 7 2 12 8 4 3 11 and postorder 9 1 2 12 7 5 3 11 4 8. What is its preorder?
- Keys 1, 2, 3, 4, 5, 6, 7 are inserted in that order into an empty AVL tree. How many rotations (counting a double rotation as one…