# 3-heap max heap

I have this 3 heap max heap that I need to write the array for it, but I'm not sure how. Would it just be

20,18,13,15,11,12,16,10,9,11,13,2,9?

• I think you just have to add the 10 1 in the end. – WhatsUp Oct 7 '19 at 6:24
• yea I did that but it was wrong – Julie G Oct 7 '19 at 6:30
• Otherwise I don't know what is "the array for it". I understand it as the array implementation of a ternary heap, as described here: en.m.wikipedia.org/wiki/D-ary_heap – WhatsUp Oct 7 '19 at 6:36

More generally for a generalized d-heap, the items may be viewed as the nodes in a complete d-ary tree, listed in breadth-first traversal order: the item at position $$0$$ of the array (using zero-based numbering) forms the root of the tree, the items at positions 1 through d are its children, the next $$d^2$$ items are its grandchildren, etc. Thus, the parent of the item at position $$i$$ (for any $$i > 0$$) is the item at position $$⌊(i − 1)/d⌋$$ and its children are the items at positions $$d\cdot i + 1$$ through $$d\cdot i + d$$.