GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Build-heap (bottom-up, max-heap) is run on [3, 9, 2, 1, 4, 5, 8, 7, 6, 10, 12, 11]. In each sift-down step the larger of the element and its existing children is found with one comparison per child present (against the current maximum). How many key comparisons are made in total during the build?
- A. 22
- B. 13
- C. 29
- D. 18
Correct answer: D. 18
Process indices 5 down to 0; each sift-down level costs one comparison per existing child. Counting every level visited gives 18.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A dynamic array starts with capacity 4. When an append finds it full, it allocates capacity c + c / 2 (integer division), copies every…
- The words tea, ten, to, inn, in, i, ted, tent, tenant, tens, ton are inserted into an initially empty trie (one node per character, root…
- An array A[-2..5][1..6][0..3] of 4-byte elements has base address 1000 (address of A[-2][1][0]). What is the address of A[3][4][2] in…
- Only the non-zero band of a 20 x 20 tridiagonal matrix (entries with |i - j| <= 1, rows and columns numbered from 1) is stored in a 1-D…
- void f(int n) { if (n <= 1) return; f(n - 1); f(n / 2); } Each activation record takes 32 bytes. What is the peak stack usage in bytes…
- void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } int main() { int a[5] = {3, 7, 9, 12, 5}; for (int i = 0; i < 5; i++) swap(&a[i], &a[4…