Python: delete element from heap
You can remove the i-th element from a heap quite easily: h[i] = h[-1] h.pop() heapq.heapify(h) Just replace the element you want to remove with the last element and remove the last element then re-heapify the heap. This is O(n), if you want you can do the same thing in O(log(n)) but you’ll need to … Read more