Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
A min-heap is built by inserting 66, 44, 32, 55, 85, 62 one by one (sift-up on each insert). After one extract-min (move the last element to the root, then sift down), what is the array?
- A. [44, 55, 62, 66, 85]
- B. [32, 55, 44, 66, 85, 62]
- C. [62, 55, 44, 66, 85]
- D. [55, 66, 44, 62, 85]
Correct answer: A. [44, 55, 62, 66, 85]
Heap after all inserts: [32, 55, 44, 66, 85, 62]. Remove the root (32), move the last element (62) to the root and sift it down to restore the min-heap property, giving [44, 55, 62, 66, 85].
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
- An undirected graph has adjacency lists A:BCG B:ACEF C:ABDEG D:C E:BC F:B G:AC. Neighbours are always explored in alphabetical order…
- A DAG has edges A→B, B→C, B→D, C→E, A→F, A→D, D→F. Using Kahn's algorithm (always picking the smallest-labelled vertex among those…
- Keys 74, 72, 41, 18, 95, 79, 69 are inserted in this order into an empty BST. What is the preorder traversal?
- An AVL tree node has left subtree height 4 and right subtree height 1. What must happen after this imbalance is detected?
- Keys 77, 23, 72, 58, 94, 42, 92 are inserted in this order into an empty BST. What is the postorder traversal?
- In the undirected graph with edges A–B:14, A–C:4, B–D:8, C–E:11, D–F:12, C–F:9, what is the shortest-path distance from A to C?