I've been reading about min heaps, currently looking at this article, and I am very confused by something.
The article makes the following statement:
If a given node is located at index 'x' in the array, its left child exists at index = 2x, and its right child exists at index = 2x + 1. Each node's parent exists at index = x / 2 (rounded down).
It gives this example:
This min heap is represented in the array [100, 19, 36, 17, 3, 25, 1, 2, 7]
.
But this doesn't jive with the preceding statement about indexing. 36
can be found at index 2
, and 2 * 2
is 4
. But index 4
is 3-- the right child of the 19 node, not the left child of the 36 node.
What am I missing here?