38 lines
1.4 KiB
Markdown
38 lines
1.4 KiB
Markdown
[alg.heap.operations.general]
|
||
|
||
# 26 Algorithms library [[algorithms]](./#algorithms)
|
||
|
||
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.heap.operations.general)
|
||
|
||
### 26.8.8 Heap operations [[alg.heap.operations]](alg.heap.operations#general)
|
||
|
||
#### 26.8.8.1 General [alg.heap.operations.general]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10877)
|
||
|
||
A random access range [a, b) is a[*heap with respect to comp and proj*](#def:heap_with_respect_to_comp_and_proj "26.8.8.1 General [alg.heap.operations.general]") for a comparator and projection comp and proj if its elements are organized such that:
|
||
|
||
- [(1.1)](#1.1)
|
||
|
||
With N = b - a, for all i, 0<i<N, bool(invoke(comp, invoke(proj, a[âiâ12â]), invoke(proj, a[i]))) is false[.](#1.1.sentence-1)
|
||
|
||
- [(1.2)](#1.2)
|
||
|
||
*a may be removed by pop_heap, or
|
||
a new element added by push_heap,
|
||
in O(logN) time[.](#1.2.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10894)
|
||
|
||
These properties make heaps useful as priority queues[.](#2.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10897)
|
||
|
||
make_heap converts a range into a heap andsort_heap turns a heap into a sorted sequence[.](#3.sentence-1)
|