6 of 6
| Operation | Time |
|---|---|
| Push | O(log n) |
| Pop | O(log n) |
| Peek (min/max) | O(1) |
| Heapify | O(n) |
heapq is min-heap onlyheap[0] on an empty heapAfter mastering heaps:
Heaps are everywhere in algorithms β keep practicing! π
Test your understanding:
i, where is its left child?Answers:
2 * i + 1heapqβ Standard library: heapq, collections, itertools, math, random, functools, datetime, bisect
β Functions, classes, recursion, print()
β No file system, subprocess, OS access, or network requests
β No pip install (all supported modules are pre-loaded)
β±οΈ 5 second execution time limit