Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A max-heap is built by inserting 55, 85, 57, 63, 32, 19, 91, 12 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. [63, 55, 85, 12, 32, 19, 57]
- B. [85, 63, 57, 55, 32, 19, 12]
- C. [91, 63, 85, 55, 32, 19, 57, 12]
- D. [12, 63, 85, 55, 32, 19, 57]
Correct answer: B. [85, 63, 57, 55, 32, 19, 12]
Heap after all inserts: [91, 63, 85, 55, 32, 19, 57, 12]. Remove the root (91), move the last element (12) to the root and sift it down to restore the max-heap property, giving [85, 63, 57, 55, 32, 19, 12].
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 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…
- 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…