Binary trees can be stored in an array as follows:
Indexing of the array starts at instead of . For an array , the root is stored at . For a node stored at , the left child, if any, is stored in and the right child, if any, in .
What should be the minimum size of array to be able to store any binary tree of vertices?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I think that the answer should be 2^h - 1 where h is the height of the tree, in this way you have almost a perfect optimization of the array's length for differents trees with the same number of nodes but with a different permutations.