3

Does an erase operation also update the heap after the element is removed?

I went through member functions explanation in boost documentation for fibonacci_heap where it is mentioned what happens after increase/decrease operations, but when it comes to erase the only thing that is stated is that it erases the element pointed by handle.

Does that mean that the heap is reformed after that? If not, what happens to the child nodes of the node that was erased? Am I missing something obvious?

LetsPlayYahtzee
  • 7,161
  • 12
  • 41
  • 65

1 Answers1

4

When erasing an element from a fibonacci heap, the tree is re-consolidated. As a general rule, when the amortized time of an operation on a fibonacci heap is O(log(N)), then tree consolidation is occuring.

Conceptually, a Delete operation can be thought of as being the combination of two operations:

  • For min-heap implementations, Delete is the combination of Decrease-Key (O(1)) and Extract-Min (O(log(n)).
  • For max-heap implementations, Delete is the combination of Increase-Key (O(1)) and Extract-Max (O(log(n)).

In practice, the implementation is often optimized to avoid unnecessary steps, but the amortized logarithmic complexity remains the same. In the case of Boost.Heap's fibonacci_heap::erase() the implementation:

  1. cuts off the link between the node and its parent
  2. moves the erase node's children to the root list
  3. consolidates the tree
Tanner Sansbury
  • 51,153
  • 9
  • 112
  • 169