GATE Computer ScienceHardGATE CS (PYQ pattern)
A complete binary tree (every level full except possibly the last, which is filled from the left) has exactly 300 leaves. Which node counts n are possible, and for the largest such n, how many leaves are NOT on the last level?
- A. only n = 599; 211 leaves
- B. n = 599 or 600; 212 leaves
- C. n = 599 or 600; 211 leaves
- D. n = 600 or 601; 211 leaves
Correct answer: C. n = 599 or 600; 211 leaves
In a complete tree the internal nodes are indices 1..floor(n/2), so leaves = n - floor(n/2) = ceil(n/2) = 300 gives n = 599 or 600. For n = 600, depths 0 to 8 hold 511 nodes and the last level holds 89; their parents are the first ceil(89/2) = 45 of the 256 nodes at depth 8, so 256 - 45 = 211 leaves sit at depth 8 (using floor(89/2) = 44 would give 212).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A rooted tree has 6 nodes with 2 children, 5 nodes with 3 children and 4 nodes with 4 children; every other node is a leaf. How many nodes…
- How many structurally different binary search trees can be built on the keys 1..7 such that the height is at most 3 (a single node has…
- Among all 429 structurally different binary search trees on the keys 1 to 7, in how many is key 3 a leaf?
- Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. An iterative preorder…
- Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. Its level-order traversal…
- Which one of the following sequences can NOT be the postorder traversal of a binary search tree with distinct keys?