- Take the number of nodes in the heap and write that number down in binary.
- Erase the most significant bit.
- Starting at the root, go to the left child when you see a zero, and go to the right child when you see a one.
- When you run out of binary digits, you will be at the last node.
Trad-off the time to lookup the last node in heap rather than storing a pointer there? Probably not worth it.
ReplyDeleteBut on a coolness rating (that's unintuitive to me at first glance) - 10/10 ;)
Agreed!
ReplyDelete