Consider an 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:

Consider an 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: Correct Answer floor (i / 2)

The correct answer is "option 3".

CONCEPT:

The binary heap is a complete binary tree with heap properties.

Binary heap is either max. heap (root value > all key values) or min. heap. (root value < all key values).

EXPLANATION:

Binary heap elements can be represented using an array with index value i (i < = n),

Parent node of element will be at index: floor (i / 2)

Left Child node will be at index: 2 * i

Right child node will be at index: 2 * i + 1

Hence, the index of the parent is floor (i / 2).

Related Questions

A teacher asked the class to subtract 5 from 75.70% of the class said: 25. Their work was shown as: \(\begin{array}{*{20}{c}} {\begin{array}{*{20}{c}} 7&5 \end{array}}\\ {\underline {\begin{array}{*{20}{c}}\ { - 5} \ \ \ &{} \end{array}} }\\ {\underline {\begin{array}{*{20}{c}} 2&5 \end{array}} } \end{array}\) Which of the following describes the most appropriate remedial action that the teacher should take to clarify this misconception?