GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 1.15

Parent index in a one-based binary heap

Data Structures · Heaps & Priority Queues · Full GATE CSE 2001 paper

GATE 2001, Q1.15 1 mark · MCQ
Report issue

Heaps & Priority Queues

Question 1.15, GATE 2001: A binary heap occupies array indices 1 through n. For an element at index i, choose the parent index from i−1, floor(i/2), ceil(i/2), and (i+1)/2. Account for the root boundary.
Tap to enlarge
Your answer
Answer & solution

Answer: B for nonroot nodes (no official key was published)

Step 1: A node at index j has left child 2j and right child 2j+1. For an even child index i=2j, division gives i/2=j. For an odd child i=2j+1, floor(i/2)=j.

Step 2: Both cases are captured by floor(i/2), B. For example indices 6 and 7 both have parent 3; ceiling would incorrectly map 7 to 4.

Boundary: The root at i=1 has no parent. The formula returns sentinel index 0, outside the heap, rather than describing a genuine parent.

Original paper, page 2