-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Misleading comment "heap.sort() maintains the heap invariant" #114466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @rhettinger |
I'm not the master of the language but "maintains the heap invariant" here means "it's still a heap" to me. I guess a possible ambiguity is that the variable itself is also |
The confusion is interpreting 'heap invariant' as noun 'heap' that is kept adjective 'invariant', unchanged. It is meant be interpreted as a compount noun meaning the invariant that characterizes a heap. In other words, 'invariant' is the noun that in maintained and 'heap' is used as a noun-adjective that specified which invariant is maintained. 'Invariant' is a math and CS term meaning a condition that characterizes an math or information structure. Unless more than one person is confused, we could close this. The term 'heap invariant' should have been defined earlier in the doc. @florensacc , please check. |
The docs do describe the invariant, but they don't use the term "heap invariant" when doing so. If. others are likely to be confused as well, maybe something like the following could be useful: Heaps are binary trees for which every parent node has a value less than or
-equal to any of its children. This implementation uses arrays for which
+equal to any of its children. We refer to this condition as the heap invariant.
+
+This implementation uses arrays for which |
Thanks for the comments, I see how the sentence is technically correct when understanding "invariant" as the noun and "heap" its noun-adjective. Defining "heap invariant" earlier like @hauntsaninja suggests would definitely help! And maybe we could also rephrase "and heap.sort() maintains the heap invariant!" as "and heap.sort() also satisfies the heap invariant!" or plainly "and heap.sort() is also a heap!". |
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.
I think "invariant" is clear / standard enough, and since OP says it would help, I've opened a PR with my suggestion. Like terryjreedy says, unless we have evidence of more confusion, I don't see a need to make further changes. |
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.
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. (cherry picked from commit 37a4cbd) Co-authored-by: Shantanu <[email protected]>
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. (cherry picked from commit 37a4cbd) Co-authored-by: Shantanu <[email protected]>
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.
Uh oh!
There was an error while loading. Please reload this page.
Documentation
In the fourth paragraph of the documentation says:
"""
These two make it possible to view the heap as a regular Python list without surprises: heap[0] is the smallest item, and heap.sort() maintains the heap invariant!
"""
This seems to suggest that
heap.sort()
does not changeheap
, although that's clearly not true:Linked PRs
The text was updated successfully, but these errors were encountered: