Search code examples
arraysdata-structuresheapbinary-treeheapsort

How to prove the conversion from a compete binary tree to an array?


A complete binary tree can be efficiently implemented as an array, where a node at index i has children at indexes 2i and 2i+1 and a parent at index floor(i/2), with one-based indexing.

If child index is greater than the number of nodes, the child does not exist.

I see these conversions every but there is no formal proof of them, can any give a strict proof or a link to it, thanks!


Solution

  • See this link Derivation of index equations This is for 0 based indexing. But also has notes on 1 based indexing