GATE Computer ScienceHardGATE CS (PYQ pattern)
A max-heap is built from [50, 30, 40, 10, 20, 35, 25, 5, 8, 15, 12] by bottom-up heapify. Two delete-max operations are then performed (each moves the last element to the root and sifts down). What is the resulting array and what is the number of swaps used by the two deletions?
- A. 35 30 25 10 20 12 15 5 8; 5 swaps
- B. 8 5 15 12 20 10 25 30 35; 4 swaps
- C. 35 30 25 20 15 12 10 8 5; 4 swaps
- D. 35 30 25 10 20 12 15 5 8; 4 swaps
Correct answer: D. 35 30 25 10 20 12 15 5 8; 4 swaps
The initial heap is 50 30 40 10 20 35 25 5 8 15 12. Each deletion replaces the root by the last leaf and sifts it down, picking the larger child each time.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many different max-heaps (valid arrays) can be formed using the 10 distinct keys 1 to 10?
- A hash table of size 11 uses linear probing with h(k) = k mod 11. Keys 43, 22, 33, 54, 65, 76, 87, 14, 25 are inserted in this order (no…
- A table of size 11 uses quadratic probing h(k, i) = (k mod 11 + i^2) mod 11. Keys 23, 34, 45, 56, 67, 78, 89 (all congruent to 1 mod 11)…
- Twenty keys are hashed into a chained table with 8 slots, each key independently and uniformly. What are the expected number of colliding…
- struct node { int d; struct node n; }; struct node f(struct node p, int k) { if (p == NULL) return NULL; struct node cur = p, prev = NULL…
- Keys 5, 3, 8, 3, 9, 1, 8, 5 are inserted one by one into an initially empty sorted singly linked list; each insertion scans from the head…