GATE Computer ScienceVery hardGATE CS (PYQ pattern)
How many structurally distinct binary trees (left and right children distinguished) with exactly 7 nodes have exactly 3 leaves?
- A. 105
- B. 134
- C. 120
- D. 84
Correct answer: C. 120
3 leaves means 2 two-child nodes and 7 - 3 - 2 = 2 one-child nodes. Count = C(6,4) x C_2 x 2^2 = 15 x 2 x 4 = 120: choose the shape pattern, then left or right for each one-child node (the Narayana count 105 is for plane trees, not binary trees).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A full binary tree has every node with 0 or 2 children; left and right are distinguished. How many structurally different full binary…
- An undirected unweighted graph has edges 1-2, 1-3, 2-4, 2-5, 3-4, 3-6, 4-7, 5-7, 6-7, 6-8, 7-9, 8-9. Using BFS from vertex 1, what is the…
- A directed graph on vertices 1..4 has edges 1->2, 1->3, 2->3, 2->4, 3->1, 3->4, 4->1, 4->2. How many walks of length exactly 4 (edges…
- An undirected graph has 14 vertices, 20 edges and exactly 3 connected components. DFS is restarted from an unvisited vertex until all…
- A complete binary tree stored in an array has 1000 nodes. What is its height (a single node has height 0) and how many nodes are at the…
- A binary tree with 25 nodes has two pointer fields per node. How many of these 50 fields hold NULL, and how many hold NULL if the tree is…