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