Data Structures & AlgorithmsHardGATE CS
A binary min-heap is stored in a 0-indexed array [13, 33, 15, 35, 42, 23, 32]. Perform, in order: insert 6, delete-min, insert 60, delete-min. (Insert appends and sifts up; delete-min moves the last element to the root and sifts it down, swapping with the smaller child.) What is the final array?
- A. [15, 33, 23, 35, 42, 60, 32]
- B. [33, 35, 15, 60, 42, 23, 32]
- C. [15, 35, 60, 33, 42, 23, 32]
- D. [15, 23, 32, 35, 60, 33, 42]
Correct answer: A. [15, 33, 23, 35, 42, 60, 32]
Sift-down must compare BOTH children and keep going until the heap property holds; doing that at every step gives [15, 33, 23, 35, 42, 60, 32]. Swapping with the left child whenever it beats the parent, or stopping after one swap, leaves a different (often invalid) array.
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
- The directed graph A→C (5), A→E (7), B→A (5), C→B (5), D→A (5), D→B (-6), E→C (9), E→D (7) has one negative edge but no negative cycle…
- Kruskal's algorithm runs on the weighted undirected graph A–C (29), A–F (19), A–G (2), B–D (8), B–G (25), C–G (14), D–F (1), E–F (11), E–G…
- How many structurally different binary trees with 5 nodes have height EXACTLY 3 (height = edges on the longest root-to-leaf path)?
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 45?
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: E→B (2), E→C (9), D→F (-3), F→A…
- The POSTORDER traversal of a BST with distinct keys is 11, 32, 67, 77, 91, 95, 94, 92, 80, 52. What are the height of the tree (edges on…