Object-Oriented Programming · Goldman Sachs · Medium
Sift-Up Insertion for a Binary Min-Heap A binary min-heap is a complete binary tree stored in a zero-indexed array. The heap property requires every node's value to be no greater than its children's values. In array form, for a node at index $$i$$, its children are at $$2i+1$$ and $$2i+2$$, and its parent is at $$ \left\lfloor \frac{i-1}{2} \right\rfloor. $$ Inserting a new value while preserving the complete-tree shape can temporarily violate the min-heap property. The fix…
Checking your access…