Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
How many structurally different binary trees with 7 nodes have height EXACTLY 5 (height = edges on the longest root-to-leaf path)?
- A. 365
- B. 144
- C. 285
- D. 32
Correct answer: B. 144
Let F(n, h) count trees with n nodes and height ≤ h: F(n, h) = Σ F(i, h−1)·F(n−1−i, h−1). Exactly 5 is F(7, 5) − F(7, 4) = 365 − 221 = 144.
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
- Keys 72, 29, 21, 18, 28, 16, 23, 33, 25, 67 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- DFS runs on the directed graph with adjacency lists A: BG; B: FG; C: AEFG; D: C; E: A; F: A; G: –, starting at A, scanning lists in the…
- A tree on vertices 1–8 has edges 2–1, 3–2, 4–2, 5–2, 6–2, 7–4, 8–3. What is the sum of the distances (in edges) over all unordered pairs…
- The weighted undirected graph A–B (1), A–C (3), A–D (5), B–D (3), B–E (6), C–D (3), D–E (6) has repeated weights. How many different…
- A DAG on vertices A–G has edges A→C, A→D, A→E, E→B, E→C, E→F, G→E, G→F. What order does Kahn's algorithm that always removes the…
- DFS on the directed graph with adjacency lists A: CDE; B: FG; C: –; D: G; E: FG; F: AG; G: – starts at A (scanning lists in the order…