Collection Kit

PairingHeap

Advanced

A PairingHeap is a type of heap that allows for efficient merging and decrease-key operations, providing good performance for priority queue implementations.

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

Key Features

  • Simple Structure: Easy to implement and understand.
  • Amortized Efficiency: Provides efficient operations through a simple merging process.

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 { PairingHeap } from "collection-kit";

const heap = new PairingHeap();
heap.insert(15);
heap.insert(10);
heap.insert(20);

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