Collection Kit

FibonacciHeap

Advanced

A FibonacciHeap is a heap data structure that allows for efficient merging of heaps and supports decrease-key operations in O(1) amortized time.

Import Statement
import { FibonacciHeap } from "collection-kit";

Key Features

  • Amortized Efficiency: Provides efficient operations through lazy merging.
  • Multiple Trees: Can consist of multiple trees, allowing for flexible structure.

Common Operations

Insert
Add a new element to the heap.
FindMin
Retrieve the minimum element without removing it.
DeleteMin
Remove and return the minimum element.
DecreaseKey
Decrease the value of a key.

Example Code

import { FibonacciHeap } from "collection-kit";

const heap = new FibonacciHeap();
heap.insert(10);
heap.insert(5);
heap.insert(20);

console.log("Min:", heap.findMin());    // 5
console.log("Delete min:", heap.deleteMin()); // 5