What kind of math do you use to traverse the 4-heap when using an array to store all the elements? Specifically, how do you find the index of a parent node to a specific leaf?
Let’s say I have the following array:
0|1|2|3|4|5|6|7|8|9|10|… etc.
with the heap then constructed from that with 1 being the root, 2..5 its children, 6..9 2’s children etc.
What exactly is the math i need if I need to find (for example) the parent of 6?
To find the parent of any child (other than 1, which has no parent):
To find the first and last child of a parent:
You can see this in operation since, at each level, you add four times as many elements as you did in the previous level:
Examples are: