Data Structures & AlgorithmsModerateGATE CS · Product-company placement
A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 139 nodes. How many leaves does it have, and how many nodes have exactly one child?
- A. 69 leaves, 0 with one child
- B. 70 leaves, 0 with one child
- C. 12 leaves, 0 with one child
- D. 70 leaves, 1 with one child
Correct answer: B. 70 leaves, 0 with one child
In array form (1-based), nodes 1..⌊n/2⌋ = 1..69 are internal, so leaves = 139 − 69 = 70; the last internal node has only a left child exactly when n is even. The 12 nodes on the last level are not all the leaves.
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 binary tree with distinct labels has INORDER E G A D B H C F I and LEVEL-ORDER D E I A F G H B C. What is its postorder traversal?
- A tree on vertices 1–11 has edges 2–1, 3–2, 4–1, 5–2, 6–3, 7–4, 8–6, 9–8, 10–8, 11–8. What is the size of a maximum independent set (no…
- A 4 × 4 grid has rows 6 6 6 4 / 7 6 5 2 / 2 9 8 2 / 5 1 8 9. Moving only right or down from the top-left to the bottom-right cell, what is…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: F→A (9), D→A (4), E→D (8), C→B…
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (1), 1→3 (5), 2→1 (1), 2→4 (8), 3→1 (3), 3→2 (9), 4→3 (2). After the…
- A tree on vertices 1–9 has edges 2–1, 3–1, 4–3, 5–2, 6–4, 7–6, 8–6, 9–8. What are its diameter and radius, and which vertex/vertices form…