Skip to main content

Class: BinomialHeap<T>

A binominal min-heap. Each element added to the heap is ordered according to the value of an assigned key relative to the keys of the other elements in the heap. The relative values of element keys are defined by a supplied comparator function. Retrieval of the element with the smallest key (minimum element) is performed in constant time. Removal of the minimum element and insertions are performed in logarithmic time (amortized to constant time in the case of insertions). Merges are also supported, with destructive merges performed in logarithmic time.

Type parameters

Name
T

Constructors

constructor

new BinomialHeap<T>(comparator): BinomialHeap<T>

Constructor.

Type parameters

Name
T

Parameters

NameTypeDescription
comparator(a: T, b: T) => numberThe function that this heap uses to compare the keys of its elements. The function returns 0 if a and b share the same key, a negative number if a has a lower key than b, and a positive number if a has a greater key than b.

Returns

BinomialHeap<T>

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:47

Accessors

size

get size(): number

The number of elements contained in this heap.

Returns

number

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:37

Methods

clear

clear(): this

Removes all elements from this heap.

Returns

this

This heap, after it has been cleared.

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:145


findMin

findMin(): undefined | T

Finds the element in this heap with the smallest key.

Returns

undefined | T

The element in this heap with the smallest key, or undefined if this heap is empty.

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:54


insert

insert(element): this

Inserts an element into this heap.

Parameters

NameTypeDescription
elementTThe element to insert.

Returns

this

This heap, after the element has been inserted.

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:99


merge

merge<U>(other, destructive?): this

Merges this heap with another one. The merge can either be non-destructive or destructive. A non-destructive merge preserves the other heap. A destructive merge clears the other heap. A destructive merge takes O(log N) time while a non-destructive merge takes O(M + log N) time, where N is either the size of this heap or the size of the other heap, whichever is larger, and M is the size of the other heap. The difference stems from the need to copy the other heap in a non-destructive merge. Note that the result of this operation is only valid if the two heaps have equivalent comparator functions.

Type parameters

Name
U

Parameters

NameTypeDefault valueDescription
otherBinomialHeap<U>undefinedThe heap to merge into this one.
destructivebooleanfalseWhether to perform a destructive merge. False by default.

Returns

this

This heap, after the merge has been completed.

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:123


removeMin

removeMin(): undefined | T

Removes and returns the element in this heap with the smallest key.

Returns

undefined | T

The removed element, or undefined if this heap is empty.

Defined in

src/sdk/utils/datastructures/BinomialHeap.ts:62