I am trying to build a min-max heap tree, here's an example of the tree structure:
- The tree is a complete binary tree
- The index in the array of the tree root is 0 and it contains no element.
- The left subtree is a min-heap and the right subtree is a max-heap.
When I am trying to implement the insertion, I meet a problem that I don't know whether the new element belongs to the min-heap or the max-heap by its index.
index_of_min_heap = {1, 3, 4, 7, 8, 9, 10, ...} index_of_max_heap = {2, 5, 6, 11, 12, 13, 14, ...}
How can I make a formula to determine the index is a min-heap index or a max-heap index? example :
is_min_or_max_heap(112) // return min or max