Data Structures & AlgorithmsModerateProduct-company placement
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 does it have, and how many nodes have exactly one child?
- A. 45 leaves, 0 with one child
- B. 28 leaves, 0 with one child
- C. 46 leaves, 0 with one child
- D. 46 leaves, 1 with one child
Correct answer: C. 46 leaves, 0 with one child
In array form (1-based), nodes 1..⌊n/2⌋ = 1..45 are internal, so leaves = 91 − 45 = 46; the last internal node has only a left child exactly when n is even. The 28 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
- 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…
- 0/1 knapsack with capacity 14: items (weight, value) = (7, 23), (4, 12), (5, 8), (4, 12), (6, 34). What is the maximum total value?
- The POSTORDER traversal of a BST with distinct keys is 10, 12, 25, 49, 53, 92, 88, 93, 76, 32. What are the height of the tree (edges on…
- Kruskal's algorithm runs on the weighted undirected graph A–C (17), A–D (12), A–E (22), A–F (4), A–G (8), B–E (18), C–D (24), C–E (19)…