{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

heaps - Heaps Heapsort Priority Queues Heaps A data...

This preview shows pages 1–4. Sign up to view the full content.

Heaps, Heapsort, Priority Queues

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Heaps : A data structure and associated algorithms, NOT GARBAGE COLLECTION A heap data structure is an array of objects than can be viewed as a complete binary tree such that: 1. Each tree node corresponds to elements of the array 2. The tree is complete except possibly the lowest level, filled from left to right The heap property is defined as an ordering relation R between each node and its descendants. For example, R could be smaller than or bigger than. In the examples that follow, we will use the bigger than relation. Example: Given array [22 13 10 8 7 6 2 4 3 5] Note that the elements are not sorted, only max element at root of tree. The height of a node in the tree is the number of edges on the longest simple downward path from the node to a leaf; e.g. height of node 6 is 0, height of node 4 is 1, height of node 1 is 3. The height of the tree is the height from the root. As in any complete binary tree of size n, this is lg n. There are 2 h nodes at level h and 2 h+1 - 1 total nodes in a complete binary tree. We can represent a heap as an array A that has two attributes: 1 Length(A) – Size of the array 2 HeapSize(A) - Size of the heap