import FibonacciHeap from '@heap-data-structure/fibonacci-heap/src/FibonacciHeap.js'
FibonacciHeap
See CLRS09 Chapter 19 on the Fibonacci Heap.
Constructor Summary
Public Constructor | ||
public |
Make-heap: creates a new empty heap. |
Member Summary
Public Members | ||
public |
compare: * |
|
public |
min: * We access a given Fibonacci heap H by a pointer H.min to the root of a tree containing the minimum key; we call this node the minimum node of the Fibonacci heap. |
Method Summary
Public Methods | ||
public |
decreasekey(ref: Node, value: Object) FIB-HEAP-DECREASE-kEY: |
|
public |
delete(ref: *) Delete ref must be internal ref.prev and ref.next get reset to null |
|
public |
head(): * Find-min: simply return the top element of the heap. |
|
public |
headreference(): * Minimum: return a pointer to the element whose key is minimum |
|
public |
increasekey(ref: Node, value: Object) Increase-key: remove the item at the key to be increased, replace the key with a larger key, then push the result back into the heap. |
|
public |
meld(other: *) Union: Uniting two Fibonacci heaps |
|
public |
merge(other: *) Synonym for FibonacciHeap#meld. |
|
public |
pop(): * |
|
public |
popreference(): * FIB-HEAP-EXTRACT-MIN(H): |
|
public |
push(value: *): * Create a new node for the inserted element and put it into the heap. |
|
public |
pushreference(ref: *): * Insert: insert new node. |
|
public |
|
Public Constructors
public constructor() source
Make-heap: creates a new empty heap.
To make an empty Fibonacci heap, the MAKE-FIB-HEAP procedure allocates and returns the Fibonacci heap object H, where H.n = 0 and H.min = NIL ; there are no trees in H. Because t(H) = 0 and m(H) = 0, the potential of the empty Fibonacci heap is pot(H) = 0. The amortized cost of MAKE-FIB-HEAP is thus equal to its O(1) actual cost.
Public Members
public compare: * source
public min: * source
We access a given Fibonacci heap H by a pointer H.min to the root of a tree containing the minimum key; we call this node the minimum node of the Fibonacci heap. If more than one root has a key with the minimum value, then any such root may serve as the minimum node. When a Fibonacci heap H is empty, H.min is NIL.
Public Methods
public delete(ref: *) source
Delete ref must be internal ref.prev and ref.next get reset to null
Params:
Name | Type | Attribute | Description |
ref | * |
public headreference(): * source
Minimum: return a pointer to the element whose key is minimum
The minimum node of a Fibonacci heap H is given by the pointer H.min, so we can find the minimum node in O(1) actual time. Because the potential of H does not change, the amortized cost of this operation is equal to its O(1) actual cost.
Return:
* |
public increasekey(ref: Node, value: Object) source
Increase-key: remove the item at the key to be increased, replace the key with a larger key, then push the result back into the heap.
public meld(other: *) source
Union: Uniting two Fibonacci heaps
The following procedure unites Fibonacci heaps H_1 and H_2, destroying H_1 and H_2 in the process. It simply concatenates the root lists of H_1 and H_2 and then determines the new minimum node. Afterward, the objects representing H_1 and H_2 will never be used again.
/!\ Assumes the same comparison function is used in both trees.
Change in potential is zero. Amortized cost is O(1), the actual cost.
Params:
Name | Type | Attribute | Description |
other | * |
public merge(other: *) source
Synonym for FibonacciHeap#meld. TODO Remove this.
Params:
Name | Type | Attribute | Description |
other | * |
public popreference(): * source
FIB-HEAP-EXTRACT-MIN(H):
Extracting the minimum node
The process of extracting the minimum node is the most complicated of the operations presented in this section. It is also where the delayed work of consolidating trees in the root list finally occurs. The following pseudocode extracts the minimum node. The code assumes for convenience that when a node is removed from a linked list, pointers remaining in the list are updated, but pointers in the extracted node are left unchanged. It also calls the auxiliary procedure CONSOLIDATE, which we shall see shortly.
Return:
* |
public push(value: *): * source
Create a new node for the inserted element and put it into the heap.
Params:
Name | Type | Attribute | Description |
value | * |
Return:
* |
public pushreference(ref: *): * source
Insert: insert new node. /!\ ref.next = ref.prev = ref which means all references that are external to the tree must reset .next and .prev and one must not call FibonacciHeap#pushreference with an internal reference from this tree or another, except the root of another tree.
Change in potential is 1. Therefore amortized cost is O(1).
Params:
Name | Type | Attribute | Description |
ref | * |
Return:
* |