Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
A max-heap is built by inserting 73, 97, 96, 27, 78, 89, 18 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. [78, 27, 96, 18, 73, 89]
- B. [96, 78, 89, 27, 73, 18]
- C. [97, 78, 96, 27, 73, 89, 18]
- D. [18, 78, 96, 27, 73, 89]
Correct answer: B. [96, 78, 89, 27, 73, 18]
Heap after all inserts: [97, 78, 96, 27, 73, 89, 18]. Remove the root (97), move the last element (18) to the root and sift it down to restore the max-heap property, giving [96, 78, 89, 27, 73, 18].
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 DAG has edges A→B, A→C, B→D, C→E, A→D, B→C. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently…
- What is the time complexity of searching for a word of length m in a trie that stores n words, independent of n?
- An undirected graph has adjacency lists A:BCEF B:AD C:ADF D:BCF E:A F:ACD. Neighbours are always explored in alphabetical order. Which is…
- An undirected graph has edges (u–v: weight) A–B:14, A–C:13, C–D:14, B–E:11, C–E:4, B–D:3. What is the weight of its minimum spanning tree?
- An undirected graph has adjacency lists A:B B:ACGH C:BDFG D:CE E:D F:C G:BC H:B. Neighbours are always explored in alphabetical order…
- Keys 47, 48, 97, 84, 52, 82, 34, 75 are inserted in this order into an empty BST. What is the height of the tree (edges on the longest…