A heap is a useful data structure when it is necessary to repeatedly remove the object with the highest (or lowest) priority, or when insertions need to be interspersed with removals of the root node.Ī common implementation of a heap is the binary heap, in which the tree is an almost complete binary tree (see figure). ![]() However, a heap is not a sorted structure it can be regarded as being partially ordered. In a heap, the highest (or lowest) priority element is always stored at the root. The heap is one maximally efficient implementation of an abstract data type called a priority queue, and in fact, priority queues are often referred to as "heaps", regardless of how they may be implemented. The node at the "top" of the heap (with no parents) is called the root node. In a min heap, the key of P is less than or equal to the key of C. In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: In a max heap, for any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C. ![]() Example of a binary max-heap with node keys being integers between 1 and 100 For the memory heap (in low-level computer programming), which is unrelated to this data structure, see C dynamic memory allocation.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |