Skip to content

Commit 37a4cbd

Browse files
authored
gh-114466: explicitly define heap invariant (#117778)
I think the choice of wording in these docs is great and doesn't need to change. However, it could be useful to explicitly define this term / the cost of doing so seems relatively low.
1 parent c2a551a commit 37a4cbd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Doc/library/heapq.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ This module provides an implementation of the heap queue algorithm, also known
1717
as the priority queue algorithm.
1818

1919
Heaps are binary trees for which every parent node has a value less than or
20-
equal to any of its children. This implementation uses arrays for which
20+
equal to any of its children. We refer to this condition as the heap invariant.
21+
22+
This implementation uses arrays for which
2123
``heap[k] <= heap[2*k+1]`` and ``heap[k] <= heap[2*k+2]`` for all *k*, counting
2224
elements from zero. For the sake of comparison, non-existing elements are
2325
considered to be infinite. The interesting property of a heap is that its
@@ -319,4 +321,3 @@ applications, and I think it is good to keep a 'heap' module around. :-)
319321
backwards, and this was also used to avoid the rewinding time. Believe me, real
320322
good tape sorts were quite spectacular to watch! From all times, sorting has
321323
always been a Great Art! :-)
322-

0 commit comments

Comments
 (0)