Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A max-heap is built by inserting 50, 84, 44, 25, 79, 86 one by one (sift-up on each insert). After one extract-max (move the last element to the root, then sift down), what is the array?
- A. [84, 79, 44, 25, 50]
- B. [79, 25, 84, 44, 50]
- C. [86, 79, 84, 25, 50, 44]
- D. [44, 79, 84, 25, 50]
Correct answer: A. [84, 79, 44, 25, 50]
Heap after all inserts: [86, 79, 84, 25, 50, 44]. Remove the root (86), move the last element (44) to the root and sift it down to restore the max-heap property, giving [84, 79, 44, 25, 50].
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 min-heap is built by inserting 60, 47, 76, 55, 61, 80, 34 one by one (sift-up on each insert). After one extract-min (move the last…
- Inserting into a binary heap of n elements (array-based, sift-up) takes worst-case time:
- Keys 12, 54, 92, 89, 71, 88, 69 are inserted in this order into an empty BST. What is the postorder traversal?
- A max-heap is built by inserting 87, 88, 19, 50, 39, 89 one by one (sift-up on each insert). After one extract-max (move the last element…
- Which traversal of a binary search tree visits the keys in ascending order?
- Which data structure does breadth-first search (BFS) use to decide which vertex to visit next?