Consider any array representation of an n element binary heap where the…

2001

Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i <= n), the index of the parent is

  1. A.

    i − 1

  2. B.

    floor(i/2)

  3. C.

    ceiling(i/2)

  4. D.

    (i + 1)/2

Attempted by 11 students.

Show answer & explanation

Correct answer: B

For a binary heap using 1-based array indexing, the parent node index is determined by dividing the child index by two. Mathematically, this relationship is expressed as floor(i divided by 2) for any node at index i.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Coding For Placement