GATE Computer ScienceModerateGATE CS
The keys 3, 9, 6, 12, 1, 15, 8 are inserted one after another into an initially empty max-heap (each insertion places the key at the end and sifts it up). The array representation of the final heap is:
- A. 15 9 12 3 1 6 8
- B. 15 12 9 3 1 6 8
- C. 15 9 12 1 3 6 8
- D. 15 12 8 9 1 3 6
Correct answer: A. 15 9 12 3 1 6 8
Insert 12: it swaps with 3 and then with 9, so the array is 12 9 6 3. Insert 1 stays at index 4. Insert 15 swaps with 6 and then 12, giving 15 9 12 3 1 6. Finally 8 sits at index 6 below 12, so no swap occurs.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int fib(int n) { if (n < 2) return n; return fib(n-1) + fib(n-2); } Including the initial call, how many times is fib executed in total…
- A hash table of size 13 uses double hashing with h1(k) = k mod 13, h2(k) = 1 + (k mod 11) and probe sequence (h1 + i·h2) mod 13. The keys…
- A dynamic array starts with capacity 1. Whenever an append finds it full, a new array of double the capacity is allocated and all current…
- In an AVL tree a single node has height 0. What is the minimum number of nodes in an AVL tree of height 6?
- int f(int n) { static int c = 0; c += n; if (n > 0) f(n - 1); return c; } int main() { int x = f(4); int y = f(2); printf("%d", x + y); }…
- Assume a 32-bit unsigned int. What does the following program print? #include <stdio.h> int main() { unsigned s = 0; for (unsigned i = 1…