Data Structures & AlgorithmsModerateGATE CS · Product-company placement
A rooted tree has 6 nodes with 1 child, 6 nodes with 2 children, 3 nodes with 3 children, and every other node is a leaf. How many leaves does it have?
- A. 12
- B. 13
- C. 16
- D. 19
Correct answer: B. 13
Edges = nodes − 1 counted two ways: Σ i·nᵢ = (n₀ + Σ nᵢ) − 1, so n₀ = 1 + Σ (i − 1)·nᵢ = 13. Nodes with one child add nothing.
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
- Edit distance between HEAPSORT and DYNAMIC where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- How many topological orderings does the DAG on vertices A–F with edges C→A, D→A, E→A, E→D, F→C, F→D, F→E have?
- An undirected connected graph has edges A–D, A–H, B–F, B–G, C–G, C–H, D–E, D–G, F–H, G–I. How many articulation points (cut vertices) and…
- Lectures occupy half-open intervals [start, end): [5, 13), [8, 13), [8, 16), [13, 16), [13, 17), [13, 18), [13, 20), [17, 22). A lecture…
- Dijkstra's algorithm runs from A on the directed graph A→D (7), B→A (6), B→E (9), C→A (3), C→D (10), D→B (11), D→F (7), E→C (9), F→A (1)…
- A tree on vertices 1–9 has edges 2–1, 3–1, 4–1, 5–3, 6–3, 7–6, 8–7, 9–6. What are its diameter and radius, and which vertex/vertices form…