GATE Computer ScienceVery hardGATE CSE
How many structurally distinct binary trees (left and right children distinguished) with exactly 7 nodes have height exactly 3, where height is the number of edges on the longest root-to-leaf path?
- A. 98
- B. 48
- C. 68
- D. 69
Correct answer: C. 68
Let T(n,h) count trees with n nodes and height ≤ h; the answer is T(7,3) − T(7,2) = 69 − 1 = 68.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int cnt = 0; for (int i = 0; i < 100; i++) for (int x = i; x; x = x & (x - 1)) cnt++; What is the final value of cnt?
- int n = 200, cnt = 0; for (int i = 1; i <= n; i = 2) for (int j = i; j <= n; j += i) cnt++; What is the value of cnt after the loops finish?
- Quicksort with Lomuto partitioning (pivot = last element of the sub-array, loop compares A[j] ≤ pivot for j from lo to hi−1) sorts [4, 9…
- The Hoare partition scheme is applied once to A = [5, 3, 8, 5, 1, 9, 5, 2, 7, 4] with pivot x = A[0] = 5, using: i = −1, j = 10; loop { do…
- A singly linked list holds 1, 2, …, 11 in order. Step 1: reverse it in consecutive groups of 4 nodes (a final group with fewer than 4…
- Infix a+bc^d^e-(f+g)h/i^j^k is converted to postfix with the usual stack algorithm: operators and "(" are pushed on a stack, an operator…