1

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?

JFMR
  • 23,265
  • 4
  • 52
  • 76
Andreas
  • 33
  • 3
  • 1
    Yes, but you need to know the index of that element which can be done. Then you can modify an element in `O(logN)` time. – srt1104 Jan 22 '20 at 16:09

0 Answers0