Intermediate Data Structures & Algorithms
Q72 / 100

In a min-heap represented as an array (0-indexed), how do you find the parent of the node at index i?

Correct! Well done.

Incorrect.

The correct answer is A) (i - 1) / 2, using integer division

A

Correct Answer

(i - 1) / 2, using integer division

Explanation

For a 0-indexed binary heap stored in an array, the parent of node i is at index floor((i - 1) / 2), while its children are at 2i + 1 and 2i + 2. This compact mapping avoids storing explicit pointers.

Progress
72/100