Which of the following array represents a binary max heap?

2015

Which of the following array represents a binary max heap?

  1. A.

    {20, 12, 15, 14, 10, 7, 8}

  2. B.

    {20, 14, 12, 16, 5, 10, 6}

  3. C.

    {20, 12, 15, 10, 11, 14, 13}

  4. D.

    {20, 12, 15, 10, 11, 16, 13}

  5. E.

    Question not attempted

Attempted by 271 students.

Show answer & explanation

Correct answer: C

A binary max heap is a complete binary tree where the value of each node is greater than or equal to the values of its children. For an array representation, the parent of the node at index i is at index (i-1)/2, and the left and right children are at indices 2i+1 and 2i+2 respectively. To verify if an array represents a binary max heap, check that for every node, its value is greater than or equal to the values of its children (if they exist). Step 1: Start from the root (index 0). For each node, check if it is greater than or equal to its left and right children. Step 2: For each node at index i, if 2i+1 < n, compare arr[i] with arr[2i+1]. If 2i+2 < n, compare arr[i] with arr[2i+2]. Step 3: If all nodes satisfy the max heap property, the array represents a binary max heap.

Explore the full course: Up Lt Grade Assistant Teacher 2025