All mock tests are FREE till 31 December — register to save your progress

Consider the array A=<4, 1, 3, 2, 16, 9, 10, 14, 8, 7>. After building heap from the array A, the depth of the heap and the right child of max-heap are _________ and _________ respectively. (Root is at level 0).

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. 3, 10

Explanation

Build-heap on ⟨4, 1, 3, 2, 16, 9, 10, 14, 8, 7⟩ gives ⟨16, 14, 10, 8, 7, 9, 3, 2, 4, 1⟩. Ten nodes fill levels 0–3, so the depth is 3, and the root's right child is 10.

More Data Structures and Algorithms questions