Created
September 26, 2023 10:34
-
-
Save nenetto/418d1d7d38c456bf78d341f78eaadc21 to your computer and use it in GitHub Desktop.
Heap Queue & Bisection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# heaps in standard list types with functions like heappush, heappop, and nsmallest | |
# Items are always removed by highest priority (lowest number) first. | |
a = [] | |
heappush(a, 5) | |
heappush(a, 3) | |
heappush(a, 7) | |
heappush(a, 4) | |
# print(heappop(a), heappop(a), heappop(a), heappop(a)) | |
# >>> 3 4 5 7 | |
# bisect module’s functions, such as bisect_left, provide an efficient binary search | |
# through a sequence of sorted items. The index it returns is the insertion point | |
# of the value into the sequence. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment