GATE Computer ScienceModerateGATE CSE
A binary heap stored in A[1..200] has the usual shape (complete binary tree, children of i at 2i and 2i+1). Taking the height of a leaf as 0, how many nodes have height exactly 2?
- A. 28
- B. 26
- C. 50
- D. 25
Correct answer: D. 25
Heights follow the leftmost path from each node; counting indices whose leftmost descendant chain has length 2 gives 25 (≈ n/2³ = 25).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int f(int n) { if (n == 0) return 0; return (n & 1) + f(n >> 1) + f(n >> 2); } What does f(100) return?
- Assume sizeof(int) = 4 and sizeof(int ) = sizeof(int ()[4]) = 8. int a[3][4]; / a[i][j] = 4i + j / int (r)[4] = a + 1; int p = (r + 1) +…
- #include <stdio.h> int main() { int a[5] = {10, 20, 30, 40, 50}; int p = (int )(&a + 1); printf("%d %d", (a + 1), (p - 2)); } What is…
- Assume sizeof(int) = 4 and every pointer is 8 bytes. int f(int a[][3], char s[]) { return sizeof(a) + sizeof(a) + sizeof(s); } int main()…
- int a[] = {5, 6, 7, 8}; int p = a; p++ += 2; (p)++; ++p += 10; ++p; What are a[0], a[1], a[2], a[3] and p - a after these statements?
- void g(int pp, int q, int k) { q += k; pp = q + 1; pp += q; q = pp; q -= k; } int main() { int a[3] = {1, 2, 3}; int p = a; g(&p, p, 4)…