Skip to content

Commit 742c46c

Browse files
final touchups
1 parent 160bc35 commit 742c46c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Doc/library/heapq.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ the compared elements exist. Elements are counted from zero. The interesting
2626
property of a min-heap is that its smallest element is always the root,
2727
``heap[0]``.
2828

29-
These two make it possible to view the heap as a regular Python list without
30-
surprises: ``heap[0]`` is the smallest item, and ``heap.sort()`` maintains the
31-
heap invariant!
32-
33-
Max-heaps satisfy the reverse invariant: every parent node node has a value
29+
Max-heaps satisfy the reverse invariant: every parent node has a value
3430
*greater* than any of its children. These are implemented as lists for which
3531
``maxheap[2*k+1] <= maxheap[k]`` and ``maxheap[2*k+2] <= maxheap[k]`` for all
3632
*k* for which the compared elements exist.
@@ -42,18 +38,22 @@ We use zero-based indexing. This makes the relationship between the index for
4238
a node and the indexes for its children slightly less obvious, but is more
4339
suitable since Python uses zero-based indexing. (b) Textbooks often focus on
4440
max-heaps, due to their suitability for in-place sorting. Our implementation
45-
favors min-heaps as they better correspond to Python lists: :meth:`list.sort`
46-
maintains the *min*-heap invariant.
41+
favors min-heaps as they better correspond to Python :class:`lists <list>`.
42+
43+
These two aspects make it possible to view the heap as a regular Python list
44+
without surprises: ``heap[0]`` is the smallest item, and ``heap.sort()``
45+
maintains the heap invariant!
4746

4847
Like :meth:`list.sort`, this implementation uses only the ``<`` operator
4948
for comparisons, for both min-heaps and max-heaps.
5049

51-
In the API below, and in this documentation, the unqalified term *heap*
50+
In the API below, and in this documentation, the unqualified term *heap*
5251
generally refers to a min-heap.
5352
The API for max-heaps is named using a ``_max`` suffix.
5453

55-
To create a heap, use a list initialized to ``[]``, or you can transform a
56-
populated list into a heap via function :func:`heapify`.
54+
To create a heap, use a list initialized as ``[]``, or transform an existing list
55+
into a min-heap or max-heap using the :func:`heapify` or :func:`heapify_max`
56+
functions, respectively.
5757

5858
The following functions are provided for min-heaps:
5959

0 commit comments

Comments
 (0)