Data Structures & AlgorithmsVery hardProduct-company placement
A min-heap holds 31 distinct keys in a 0-indexed array (a full tree with 5 levels). At how many different indices can the 3rd-smallest key possibly be?
- A. 2
- B. 7
- C. 4
- D. 6
Correct answer: D. 6
The 3rd-smallest key has at most 2 smaller keys, so all its ancestors come from them: it sits at depth 1 to 2, and every such slot is reachable. That is 2 + 4 + … + 2^2 = 6 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
- In how many ways can a convex polygon with 8 vertices be divided into triangles by non-crossing diagonals?
- In how many different ways can 'pineapplepen' be split into a sequence of words from the dictionary {pine, apple, pen, pineapple…
- The weighted undirected graph A–B (13), A–C (17), B–C (27), B–F (28), C–D (1), C–E (9), C–F (3), E–F (12) has a unique MST. What is the…
- Dijkstra's algorithm runs from A on the directed graph A→D (15), B→A (1), B→C (13), B→F (10), C→D (6), C→F (11), D→B (2), D→E (14), D→F…
- The POSTORDER traversal of a BST with distinct keys is 17, 16, 34, 44, 51, 66, 59, 85, 93, 46. What are the height of the tree (edges on…
- 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…