Data Structures & AlgorithmsModerateProduct-company MCQ pattern
How many structurally different binary search trees can be built from 4 distinct keys?
- A. 14
- B. 24
- C. 5
- D. 16
Correct answer: A. 14
The count is the Catalan number C₄ = C(8, 4)/5 = 14: choose each key as the root and multiply the counts for the left and right subtrees (5 + 2 + 2 + 5). 24 counts insertion orders, and many orders give the same tree.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Using the master theorem, what is the solution of T(n) = 4T(n/2) + n²?
- What is the solution of T(n) = T(n/3) + T(2n/3) + n?
- What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?
- What is the edit distance (insert, delete, replace, each cost 1) between FLASK and FLOSSY?
- In how many ways can 10 be made from coins of 2, 3 and 5 (unlimited supply, order does not matter)?
- 0/1 knapsack, capacity 7. Items (weight, value): (1, 1), (3, 4), (4, 5), (5, 7). What is the maximum total value?