GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A max-heap is built from [90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65] by bottom-up heapify. Then the key at index 14 is increased to 85 and the key at index 8 (in the array after the first operation) is increased to 100, each followed by sift-up. How many swaps do the two sift-ups perform together, and what is the root afterwards?
- A. 5 swaps, root 100
- B. 6 swaps, root 100
- C. 5 swaps, root 90
- D. 4 swaps, root 100
Correct answer: A. 5 swaps, root 100
The heapified array is 90 80 70 60 50 45 65 20 10 15 25 35 40 55 30. Increasing index 14 to 85 swaps up 2 time(s); increasing index 8 to 100 swaps up 3 times to the root.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Two stacks (values and operators) evaluate 12-(3+4(5-2))/53+8/(1+1) with all operators left-associative and integer division truncating…
- How many index pairs i < j satisfy a[i] + a[j] == 10 in the array {3, 8, 5, 2, 7, 4, 6, 1, 9, 5, 3, 7}?
- unsigned x = 0x369; / binary 11 0110 1001 / unsigned s = 0, c = 0; while (x) { unsigned t = x & -x; c++; s += t c; x -= t; } What is s…
- int a[3][4] = {{3,1,4,1},{5,9,2,6},{5,3,5,8}}; int t = 0; for (int j = 0; j < 4; j++) for (int i = 0; i < 3; i++) t += ((a + i) + j) (j +…
- A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never…
- unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u"…