edited by
6,177 views
19 votes
19 votes

Which of the following sequences of array elements forms a heap?

  1. $\{23, 17, 14, 6, 13, 10, 1, 12, 7, 5\}$
  2. $\{23, 17, 14, 6, 13, 10, 1, 5, 7, 12\}$
  3. $\{23, 17, 14, 7, 13, 10, 1, 5, 6, 12\}$
  4. $\{23, 17, 14, 7, 13, 10, 1, 12, 5, 7\}$
edited by

1 Answer

Best answer
18 votes
18 votes

For a heap(max heap) parent should be greater than or equal to children. in a heap of $[1..n]$ left child of ith node will be at $2*i$ th position and right child will be at $2*i+1$ position.

So, for given options we can verify it.
.
Option C seems to be following the property.

Answer:

Related questions

44 votes
44 votes
5 answers
2
Rucha Shelke asked Sep 16, 2014
20,571 views
In a binary max heap containing $n$ numbers, the smallest element can be found in time $O(n)$ $O(\log n)$ $O(\log \log n)$ $O(1)$