MinMax Heap implementation without array

I found many MinMax Heap implementations that store data in an array. It is very simple to implement, so I'm looking for something else. I want to create a MinMax Heap using only heap elements with pointers to the left child and right child elements (and touching the key for comparison). Thus, the heap has only a pointer to the root object (minimum level), and the root object has a pointer to its children (maximum level), etc. I know how to insert a new object (find the correct path using the binary representation of int depending on the size of the heap), but I do not know how to implement the rest (push up (down) element, find a parent or grandfather).

thanks for reference

+3
source share
3 answers

, , . node: .

+2

heapq , . , arr[2*n+1] node.left arr[2*n+2] node.right. , arr[(n-1)>>1], node , node.parent.

, . treaps, Lisp, .

+1

This is a tough binary heap implementation without an array. Because you have to hold all of the parent during insertion, and then perform the operation by pressing up and down. for example [parent_1, parent_2 ... parant_k] and then if parent_(k+1) < parant_k pushUpand change their right child and left child elements

-2
source

Source: https://habr.com/ru/post/1785589/


All Articles