Fibonacci Heap Operations

Fibonacci Heap – Insertion and Union


Fibonacci Heap is a collection of trees with min-heap or max-heap property. In Fibonacci Heap, trees can can have any shape even all trees can be single nodes (This is unlike Binomial Heap where every tree has to be Binomial Tree).
In this article, we will discuss Insertion and Union operation on Fibonacci Heap.

Insertion:
 To insert a node in a Fibonacci heap H, the following algorithm is followed:
  1. Create a new node ‘x’.
  2. Check whether heap H is empty or not.
  3. If H is empty then:
    • Make x as the only node in the root list.
    • Set H(min) pointer to x.
  4. Else:
    • Insert x into root list and update H(min).
Example:
Union: Union of two Fibonacci heaps H1 and H2 can be accomplished as follows:
  1. Join root lists of Fibonacci heaps H1 and H2 and make a single Fibonacci heap H.
  2. If H1(min) < H2(min) then:
    • H(min) = H1(min).
  3. Else:
    • H(min) = H2(min).

Example:

Comments

Popular posts from this blog

Fibonacci Heap

Tracable and Non Tracable problems

Amortized analysis- Splay Tree