Loading tutorials
i, the parent is at (i - 1) // 2. In a min-heap, every parent is less than or equal to its children.3 min readi at 2*i + 1 and 2*i + 2), and the sift-up insertion from the previous chapter. You should also be comfortable reading O(log n).3 min readi at 2i+1 and 2i+2), and the sift up and sift down routines from the previous chapters. Here you will see where the O(log n) bound comes from and what it does and does not cover.2 min readMinHeap by hand. In production code you use the standard library module heapq instead.3 min readheapq from the previous chapter. Here you will learn three techniques that cover most real uses of heapq: getting a max-heap, attaching a payload to a priority, and keeping equal priorities in a predictabl2 min readi is (i - 1) // 2, children are 2i + 1 and 2i + 2) and the sift-down operation. You should also be comfortable with Big-O notation.3 min readheapq functions heappush, heappop and heapreplace. It also assumes you know that heapq is a min-heap, so heap[0] is the smallest item.3 min readheapq works, and what a weighted graph is. Dijkstra's algorithm finds the shortest distance from one source node to every other node. It requires all edge weights to be zero or positive.3 min readheapq, know that push and pop cost O(log n), and can read Python generators. Here you will merge k sorted inputs into one sorted output with a heap that holds at most k items.2 min readheapq, and how Dijkstra's algorithm uses a priority queue.2 min read