0

I wanted to ask about Fibonacci heaps. If I have this scenario:

A
|
B

Then, we add two more nodes C and D:

A
|\
B C
  |
  D

Now we delete B:

A
|
C
|
D

Now we add E and F.

I saw it creates a tree like that:

E
|\
F A
  |
  C
  |
  D

But I don't understand why E and F are connected with the tree. From what I read, we connect trees with the same rank (for example, a tree of one node with another tree of one node), am I wrong?

Thank you very much.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Rotem
  • 13
  • 3

1 Answers1

0

If you add the nodes C and D into the first Fibonacci heap, you would not end up with the tree you drew. Instead, you'd have this heap:

    A   C   D
    |
    B

Remember that Fibonacci heaps lazily add each newly added value to the top-level list of trees and only coalesce things on a deletion. If you were to delete B, you'd promote it to the top level, like this:

    A   B   C   D

You'd then remove B:

    A   C   D

Now, you'd scan the root list and coalesce the trees of the same order together. Let's suppose you scan the nodes in the order A, C, D. First, you'll coalesce A and C together, like this:

   A   D
   |
   C

At this point, no further coalesces will happen, since there's exactly one tree of each order.

If you then add in E and F, you'd put them at the top level, like this:

   A   D   E   F
   |
   C

So yes, you're right, those nodes shouldn't get added into the tree.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065