GATE Computer ScienceVery hardGATE CS (PYQ pattern)
How many structurally distinct binary search trees on keys 1..7 have key 4 at the root and height exactly 3 (a single node has height 0)?
- A. 24
- B. 25
- C. 1
- D. 31
Correct answer: A. 24
Root 4 leaves 3 keys on each side, 5 shapes per side (C3 = 5), 25 trees in all. The height is 3 when at least one side is a chain of 3 (height 2): sides of height at most 1 give 1 shape (perfect) so 24 trees have height exactly 3.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- char s = "abracadabra"; int c[26] = {0}, i; for (i = 0; s[i]; i++) c[s[i] - 'a']++; int best = 0; for (i = 1; i < 26; i++) if (c[i] (i +…
- For n = 7 distinct keys, what is the maximum number of swaps that the bottom-up (Floyd) build-heap for a max-heap can perform, over all…
- The stock span of day i is the number of consecutive days ending at i (including i) whose price is at most the price on day i. Prices are…
- The largest rectangle in a histogram with bar heights 2, 1, 5, 6, 2, 3, 4, 1, 3 (unit widths) is found with a stack of indices; a sentinel…
- void insert(Stack s, int x) { if (empty(s) || top(s) <= x) { push(s, x); return; } int y = pop(s); insert(s, x); push(s, y); } void…
- Kahn's topological sort uses a FIFO queue seeded with all vertices of in-degree 0 in increasing order; vertices are dequeued, and…