Data Structures & AlgorithmsModerateGATE CS · Product-company placement
A rooted tree has 7 nodes with 1 child, 4 nodes with 2 children, 8 nodes with 3 children, 7 nodes with 4 children, and every other node is a leaf. How many leaves does it have?
- A. 41
- B. 42
- C. 27
- D. 49
Correct answer: B. 42
Edges = nodes − 1 counted two ways: Σ i·nᵢ = (n₀ + Σ nᵢ) − 1, so n₀ = 1 + Σ (i − 1)·nᵢ = 42. 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
- DFS runs on the directed graph with adjacency lists A: BDE; B: E; C: AE; D: BF; E: –; F: BCG; G: –, starting at A, scanning lists in the…
- The weighted undirected graph A–E (19), A–F (20), B–F (2), C–D (25), C–E (10), C–F (7), D–E (18), D–F (8) has a unique MST. What is the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 91 nodes. How many leaves…
- What is the minimum number of edges m such that EVERY simple undirected graph with 13 vertices and m edges is guaranteed to be connected?
- Keys 51, 83, 75, 67, 42, 93, 22, 21, 38, 81 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- In how many different ways can 'aaaaaa' be split into a sequence of words from the dictionary {a, aa, aaa} (every character used, order…