





























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























































Heaps (Priority Queues)
A heap is a data structure which supports efficient implementation of three operations: insert, findMin, and deleteMin. (Such a heap is a min-heap, to be more precise.)
Two obvious implementations are based on an array (assuming the size n is known) and on a linked list. The comparisons of their relative time complexity are as follows:
insert findMin deleteMin Sorted array O( n ) O(1) O(1) (from large (to move (find at end) (delete the end) to small) elements) Linked list O(1) O(1) O( n ) (append) (a pointer to Min) (reset Min pointer)
Left child of the root
The second node is always the left child of the root.
Right child of the root
The third node is always the right child of the root.
The next nodes always fill the next level from left-to-right.
A heap is a
certain kind
of
complete
binary tree.
The "heap property" requires that each node's key is >= the keys of its children