Module heap.imperative.api

This file implements the classical imperative binary min-heaps that are described in the chapter 6.1 of Cormen's "Introduction to Algorithms".

The heaps are implemented as binary trees, but concretely, the values are stored inside an array. Moreover, the data structure ensures that the values inside the array are always consecutive.

This implementation is imperative and acts on the heaps via side-effects.

const aHeap = H.empty();
[7, 6, 5, 4, 3, 2, 1].forEach((aVal) => {
H.insert(aHeap, aVal);
});
aHeap; // -> { elems: [1,4,2,7,5,6,3] }[7]

Index

Functions