Data Structures & AlgorithmsModerateGATE CS
A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 187 nodes. How many leaves does it have, and how many nodes have exactly one child?
- A. 93 leaves, 0 with one child
- B. 60 leaves, 0 with one child
- C. 94 leaves, 0 with one child
- D. 94 leaves, 1 with one child
Correct answer: C. 94 leaves, 0 with one child
In array form (1-based), nodes 1..⌊n/2⌋ = 1..93 are internal, so leaves = 187 − 93 = 94; the last internal node has only a left child exactly when n is even. The 60 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
- The directed graph A→C (4), A→E (5), B→A (6), C→B (8), D→C (1), E→B (9), E→C (-6), E→D (2) has one negative edge but no negative cycle…
- Prim's algorithm starts at F on the weighted undirected graph A–C (28), A–D (6), A–F (3), A–G (7), B–C (14), B–F (26), C–D (21), C–E (19)…
- How many topological orderings does the DAG on vertices A–F with edges C→F, D→A, D→F, E→A, F→A, F→B, F→E have?
- A tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–4, 7–6, 8–3, 9–7, 10–8. What is the size of a minimum DOMINATING set (every vertex…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [13, 15…
- Unit-time jobs (deadline, profit): J1 (2, 63), J2 (1, 38), J3 (2, 38), J4 (4, 52), J5 (2, 86), J6 (1, 75), J7 (1, 40). One job runs at a…