GATE Computer ScienceVery hardGATE CS
A segment tree over positions 0 to 12 (13 elements) is built recursively: the root is node 1, the node for [lo, hi] splits at mid = (lo + hi)/2 (integer division) and its children are 2i and 2i + 1. What is the largest node index used?
- A. 26
- B. 25
- C. 29
- D. 31
Correct answer: C. 29
A tree over 13 leaves has 2·13 − 1 = 25 nodes, but the recursive numbering leaves gaps because the tree is not perfectly balanced. The largest index belongs to position 11, reached by 1 → 3 → 7 → 14 → 29, so an array of size 30 is needed, whereas the textbook bound 2^(⌈log₂13⌉+1) − 1 = 31 is only an upper bound.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A B-tree with minimum degree t = 3 (every node except the root has between 2 and 5 keys) is built with the CLRS insertion procedure, which…
- Items 1, 2, 3, 4, 5 arrive in this order and are inserted, each at either the front or the back of a double-ended queue (the choice is…
- A tree has 16 nodes numbered 0 to 15 with the parent array parent[1..15] = 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 9, 9, 10 (node i has parent…
- The same 16-node tree (parent array 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 9, 9, 10 for nodes 1 to 15, root 0) is to be cut by deleting edges…
- A binary tree is given in preorder with # for an empty child: 1 2 4 8 # # 9 # # 5 # 10 # # 3 6 # 11 # # 7 12 # # 13 # #. What is the…
- An undirected graph on vertices 0 to 7 has the edges 0-1, 0-2, 0-3, 1-2, 1-4, 2-3, 2-5, 3-4, 3-5, 4-5, 4-6, 5-6, 5-7, 6-7. Let A be its…