Find the parent without a pointer
transcript
A heap is drawn as a tree. But it stores no pointers. No links at all. It lives in one plain array of numbers. So how does it find a parent? With one line of maths.
Write the tree level by level. Ten is cell zero. Its children are cells one and two. Cell four holds forty. Its parent is cell four minus one, halved. That is cell one. Found.
The parent is i minus one, halved. The left child is two i plus one. The right child is two i plus two. These formulas count from zero, not from one.
The tree is complete, with no holes. No gaps in the levels. So every cell maps to one place in the tree. A heap uses one cell for each item.
No pointers are stored. Index maths finds every link. Try it in the sandbox. Full breakdown in the lecture.