So I've read up on heaps, and I understand the basic concept,
but not how to actually implement it.
Basically, my issue is
How you know where to put a new node?
How you know which node to replace the root with when you delete?
So I've read up on heaps, and I understand the basic concept,
but not how to actually implement it.
Basically, my issue is
How you know where to put a new node?
How you know which node to replace the root with when you delete?
How do you know where to put a new node?
Typically, although we conceptualize binary heaps as binary trees, we represent them implicitly within an array, with the elements laid out in the order you’d find them in a top-to-bottom, left-to-right scan of the tree. This makes it easy to determine where the new node goes - you place it at the end of the array after all the previous elements.
How you know which node to replace the root with when you delete?
The standard algorithm for replacing the root goes like this: