Data Structures & AlgorithmsModerateInfosys · Wipro pattern
The minimum is deleted from the min-heap [2, 5, 3, 9, 6, 4, 8] (0-indexed): the last element moves to the root and sifts down, swapping with its smaller child. What is the array afterwards?
- A. [3, 5, 8, 9, 6, 4]
- B. [5, 3, 4, 9, 6, 8]
- C. [3, 5, 4, 9, 6, 8]
- D. [3, 4, 5, 9, 6, 8]
Correct answer: C. [3, 5, 4, 9, 6, 8]
8 moves to the root: [8, 5, 3, 9, 6, 4]. Its smaller child is 3 → swap: [3, 5, 8, 9, 6, 4]. At index 2, 8's only child is 4 → swap: [3, 5, 4, 9, 6, 8]. Stopping after the first swap gives [3, 5, 8, 9, 6, 4]; swapping with the LARGER child would put 5 on top.
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 6 vertices with degrees 3, 3, 2, 2, 2 and x, and it has 8 edges. What is x?
- Dijkstra's algorithm runs from S on the directed graph S→A (7), S→B (2), B→A (3), B→C (8), A→C (1), A→D (6), C→D (2). In what order are…
- What is the maximum number of edges in a directed ACYCLIC graph with 6 vertices (no parallel edges)?
- What is the length of the longest common subsequence of PLACEMENT and COMPLETE?
- Keys 15, 10, 20, 8, 12, 25, 6, 11, 13, 9 are inserted into an empty BST. What is the height of the tree (edges on the longest root-to-leaf…
- Keys 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?