Suppose I build a min heap:
std::vector<int> h;
...
std::make_heap(h.begin(), h.end(), std::greater<int>());
Then I modify an arbitrary heap element:
h[7] = 0;
The heap property is then broken after this modification so I cannot rely on std::heap_push
or std::heap_pop
any longer.
I know I can use std::make_heap
on h
again to rebuild the heap but it takes linear time.
Is there any way to modify an element of the min heap and rebuild the heap in sublinear time?