Data Structures & AlgorithmsVery hardGATE CS · Advanced
How many structurally different binary search trees can be built on the keys 1, 2, ..., 8 (all distinct shapes, one per key set) whose height, counted in edges on the longest root-to-leaf path, is exactly 4?
- A. 470
- B. 480
- C. 94
- D. 376
Correct answer: D. 376
Let c(n, H) count shapes of height at most H via c(n,H) = sum c(i,H-1) c(n-1-i,H-1). Exactly 4 is c(8,4) - c(8,3) = 470 - 94 = 376.
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
- A rooted tree has the vertices A–M with root A, given by parents: A is the parent of B, B is the parent of C, B is the parent of D, B is…
- A weighted undirected graph on A–H has the edges (weights): A–D (16), A–E (22), A–F (26), A–G (5), A–H (4), B–C (9), B–H (23), C–D (13)…
- Keys 45, 25, 65, 15, 35, 55, 75, 30 are inserted in this order into an empty binary search tree. What is its postorder traversal?
- What is the maximum number of nodes in a binary tree of height 5, where the height is the number of edges on the longest root-to-leaf path?
- A complete binary tree stored level by level has exactly 40 nodes. How many of them are leaves?
- Keys 14, 8, 11, 5, 9, 3, 12 are inserted one at a time into an initially empty binary min-heap kept in an array. What does the array hold…