Data Structures & AlgorithmsHardProduct-company MCQ pattern
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 elements one by one into an initially empty heap takes O(n log n) in the worst case. (iii) Finding the maximum in a min-heap takes O(log n). (iv) Heap sort is stable.
- A. Only one
- B. Only two
- C. Only three
- D. All four
Correct answer: B. Only two
(i) and (ii) are true: most nodes are near the bottom and sift down only a little, so bottom-up building sums to O(n). (iii) is false: the maximum is among the ~n/2 leaves, so it takes O(n). (iv) is false: heap sort can reorder equal keys.
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 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…
- What is the maximum possible height of an AVL tree with 20 nodes (a single node has height 0)?