Heap as array
Jump to navigation
Jump to search
General information
Abstract Data Structure: Bounded priority queue
Implementation Invariant:
- For each object of "Heap as array", there is
- a specific maximum number of items
, which is constant throughout the object's lifetime. - a current number of items
, which is dynamically changing, but it is at any time.
- a specific maximum number of items
- There is an internal type heap item with two components:
- a component named
of type - a component named
, which is a natural number and ranges from .
- a component named
- There is an array
with index range and component type heap item. The currently stored items are . - There is an index handler
with maximum size and value type . For each used index , the associated value is the position of one of the heap items in . As long as this heap item is stored, is permanently associated with this heap item (and can hence be used to locate and access this heap item at any time). The correspondence between the heap items and these numbers is one-to-one. - Heap property: For each
, it is .
The heap property may be viewed as follows: Imagine a binary tree of
- The root is indexed
. - For a node with
, the left child (if existing) has index , and the right child (if existing) has index .
Now associate the node with index
In particular, the minimum key is associated with the root.
Remark
The implementations of the methods Bounded priority queue: number and Bounded priority queue: find minimum are trivial and, hence, left out here.