|
7 | 7 | *
|
8 | 8 | * Heap Data structure
|
9 | 9 | *
|
10 |
| - * Heaps can be used as an array. For any key at array position I, |
11 |
| - * left child is at ( 2i ), right child is at ( 2i+1 ) and parent is |
12 |
| - * at (int) (i / 2). Heap size is stored at index 0. |
| 10 | + * In computer science, a heap is a specialized tree-based data structure that |
| 11 | + * satisfies the heap property: If A is a parent node of B then the key of node |
| 12 | + * A is ordered with respect to the key of node B with the same ordering applying |
| 13 | + * across the heap. Heaps can be classified further as either a "max heap" or |
| 14 | + * a "min heap". In a max heap, the keys of parent nodes are always greater |
| 15 | + * than or equal to those of the children and the highest key is in the root node. |
| 16 | + * In a min heap, the keys of parent nodes are less than or equal to those of |
| 17 | + * the children and the lowest key is in the root node. Heaps are crucial in |
| 18 | + * several efficient graph algorithms such as Dijkstra's algorithm, and in |
| 19 | + * the sorting algorithm heapsort. A common implementation of a heap is the |
| 20 | + * binary heap, in which the tree is a complete binary tree (see figure). |
13 | 21 | *
|
14 | 22 | * Basic operations of a heap are:
|
15 | 23 | *
|
16 |
| - * 1. Insert – Insert an key. |
17 |
| - * 2. Delete minimum – Delete and return the smallest item in the heap. |
| 24 | + * 1. Push – Insert an key. |
| 25 | + * 2. Pop – Delete and return the smallest item in the heap. |
| 26 | + * 3. Remove - Remove an element |
18 | 27 | *
|
19 | 28 | * http://en.wikipedia.org/wiki/Binary_heap
|
20 | 29 | ******************************************************************************/
|
|
0 commit comments