GATE Computer ScienceHardGATE CS (PYQ pattern)
In an AVL tree a single node has height 0. What is the minimum number of nodes in an AVL tree of height 6?
- A. 32
- B. 33
- C. 54
- D. 40
Correct answer: B. 33
The minimal AVL tree of height h has a minimal subtree of height h−1 and one of height h−2 under the root: N(h) = N(h−1) + N(h−2) + 1 with N(0) = 1, N(1) = 2. This gives 4, 7, 12, 20, 33 for h = 2 to 6.
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) { 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…
- Assume uint16t is a 16-bit unsigned type, int is 32 bits and the characters are ASCII. What is printed? uint16t h = 7; for (const char p =…
- int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int mul(int a, int b) { return a b; } int main() { int…
- Hoare partition on a[0..8] = {8, 3, 9, 1, 8, 5, 2, 7, 6}: int hoare(int a[], int lo, int hi) { int p = a[lo], i = lo - 1, j = hi + 1…
- A singly linked list has a tail of 6 nodes leading into a cycle of 9 nodes. A pointer 'slow' moves 1 node per step and a pointer 'fast'…