Heap grandparent

Apr 14, 2016 at 11:03pm
I'm about to code a min-max heap using a vector, and in order to do so I need to be able to access an element's parent and grandparent. I know that the formula for the index of one's parent is the floor of:

(index - 1)/2

So for the grandparent, I figured I could just apply the same formula twice, resulting in the formula:

(index - 3)/4

Do you think this is a fair conclusion for finding the grandparent?
Last edited on Apr 15, 2016 at 3:36am
Topic archived. No new replies allowed.