Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
A min-heap holds 63 distinct keys in a 0-indexed array (a full tree with 6 levels). At how many different indices can the 5th-smallest key possibly be?
- A. 4
- B. 30
- C. 31
- D. 16
Correct answer: B. 30
The 5th-smallest key has at most 4 smaller keys, so all its ancestors come from them: it sits at depth 1 to 4, and every such slot is reachable. That is 2 + 4 + … + 2^4 = 30 positions (never the root).
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
- Keys 20, 94, 97, 28, 21, 78, 37, 93, 79, 36 are inserted into an empty AVL tree (giving preorder 78, 28, 21, 20, 37, 36, 93, 79, 94, 97)…
- Dijkstra's algorithm runs from A on the directed graph A→B (14), A→C (11), A→D (8), A→E (1), A→F (15), B→C (6), B→E (2), B→F (5), C→D (9)…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: E→D (9), A→B (6), F→A (-3), F→D…
- Prim's algorithm starts at D on the weighted undirected graph A–D (23), A–F (5), A–G (28), B–C (17), B–E (15), B–G (2), C–E (21), C–G…
- A binary search tree holds exactly the keys 41, 50, 62, 63, 68, 69, 74, 94. Which ONE of the following can be its POSTORDER traversal?
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [58, 57, 54, 33, 11, 34, 22, 42, 30, 19]. After…