Skip to main content

Min Heap

A binary min-heap priority queue where the smallest element is always at the root.

Usage​

import { MinHeap } from 'athro';

const heap = new MinHeap();
heap.insert(8);
heap.insert(3);
heap.insert(6);

heap.peek(); // 3
heap.extractMin(); // 3
heap.size(); // 2

Available Methods​

MethodDescription
insert(value)Add a value to the heap
extractMin()Remove and return the minimum
peek()View the minimum without removing
size()Number of elements
isEmpty()Whether the heap is empty

Time Complexity​

OperationComplexity
InsertO(log n)
Extract minO(log n)
PeekO(1)