August 2024
Intermediate to advanced
516 pages
11h 47m
English
While the insertion algorithm seems straightforward, there’s one little snag. The first step has us place the new value as the heap’s last node. But this begs the question: how do we find the spot that will be the last node?
Let’s take a look again at the heap before we inserted the 40:

We know by looking at the diagram that to make the 40 into the last node, we’d make it the right child of the 8, as that’s the next available spot in the bottom row.
But a computer doesn’t have eyeballs and doesn’t see the heap as a bunch of rows. All it sees is the root node, and it can follow links to child nodes. So how do we create ...
Read now
Unlock full access