Skip to content

Class.MinHeap

GitHub Action edited this page Jul 6, 2025 · 17 revisions

API Reference / MinHeap

Class: MinHeap

Defined in: min-heap.ts:6

A min heap: the lowest number contained in the heap will always be on top.

Extends

Constructors

Constructor

new MinHeap(): MinHeap

Returns

MinHeap

Inherited from

AbstractHeap.constructor

Properties

heap

protected heap: number[] = []

Defined in: abstract-heap.ts:6

Inherited from

AbstractHeap.heap

Methods

insert()

insert(data): void

Defined in: abstract-heap.ts:26

Inserts data into the heap and bubbles it up to its proper location within the heap.

Parameters

data

number

The data to insert.

Returns

void

Inherited from

AbstractHeap.insert


pop()

pop(): number

Defined in: abstract-heap.ts:36

Removes the extremum of the heap and returns it.

Returns

number

data of type T

Inherited from

AbstractHeap.pop


peek()

peek(): number

Defined in: abstract-heap.ts:56

Returns the extremum of the heap without removing it.

Returns

number

data of type T

Inherited from

AbstractHeap.peek


size()

size(): number

Defined in: abstract-heap.ts:69

Returns the number of items in the heap.

Returns

number

The number of items in the heap.

Inherited from

AbstractHeap.size


isEmpty()

isEmpty(): boolean

Defined in: abstract-heap.ts:78

Returns true if the heap contains no items.

Returns

boolean

A boolean value indicating whether or not the heap is empty.

Inherited from

AbstractHeap.isEmpty


parent()

protected parent(i): number

Defined in: abstract-heap.ts:87

Returns the index of the parent of the element at i.

Parameters

i

number

Returns

number

The index of the parent of the element at i.

Inherited from

AbstractHeap.parent


leftChild()

protected leftChild(i): number

Defined in: abstract-heap.ts:96

Returns the index of the left child of the element at i.

Parameters

i

number

Returns

number

The index of the left child of the element at i.

Inherited from

AbstractHeap.leftChild


rightChild()

protected rightChild(i): number

Defined in: abstract-heap.ts:105

Returns the index of the right child of the element at i.

Parameters

i

number

Returns

number

The index of the right child of the element at i.

Inherited from

AbstractHeap.rightChild


swap()

protected swap(i, j): void

Defined in: abstract-heap.ts:115

Swaps the values of the elements at indices i and j.

Parameters

i

number

The index of the first element to swap.

j

number

The index of the second element to swap.

Returns

void

Inherited from

AbstractHeap.swap


heapifyDown()

protected heapifyDown(i): void

Defined in: min-heap.ts:13

Moves the item at index i down in the heap as long as it is greater than one of its children.

Parameters

i

number

The index whose value should be bubbled down through the heap.

Returns

void

Overrides

AbstractHeap.heapifyDown


heapifyUp()

protected heapifyUp(i): void

Defined in: min-heap.ts:41

Moves the item at index i up in the heap as long as it is less than its parent.

Parameters

i

number

The index whose value should be bubbled up through the heap.

Returns

void

Overrides

AbstractHeap.heapifyUp