GATE Computer ScienceVery hardGATE CSE · ISRO
Keys 40, 20, 60, 10, 30, 50, 70, 5, 15, 25, 35, 45, 55, 65, 80, 3, 12, 23, 27, 90 are inserted into an empty BST. How many nodes have a left subtree that is strictly taller than their right subtree (an empty subtree has height 0, a single node has height 1)?
- A. 4
- B. 2
- C. 3
- D. 6
Correct answer: C. 3
Computing subtree heights bottom-up and comparing left versus right at each of the 20 nodes gives 3 such nodes.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- In a knockout (tournament-tree) method, what is the minimum number of comparisons needed in the worst case to find both the smallest and…
- 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…
- 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()…