Constructors
constructor
Parameters
Optional initArr: T []
Default value comparator: ComparatorFn < T > = genericComparator
Methods
__@iterator
__@iterator( ) : Iterator < T >
find
Parameters
Returns number
Private getLeftChild
getLeftChild( idx: number ) : T
Private getLeftChildIdx
getLeftChildIdx( parentIdx: number ) : number
Parameters
Returns number
Private getParent
getParent( idx: number ) : T
Private getParentIdx
getParentIdx( childIdx: number ) : number
Parameters
Returns number
Private getRightChild
getRightChild( idx: number ) : T
Private getRightChildIdx
getRightChildIdx( parentIdx: number ) : number
Parameters
Returns number
Private hasLeftChild
hasLeftChild( idx: number ) : boolean
Parameters
Returns boolean
Private hasRightChild
hasRightChild( idx: number ) : boolean
Parameters
Returns boolean
Protected isCorrectOrder
isCorrectOrder( elA: T , elB: T ) : boolean
Parameters
Returns boolean
Private reBalance
reBalance( idx: number ) : void
remove
Parameters
Returns boolean
replace
replace( oldValue: T , newValue: T ) : boolean
Parameters
Returns boolean
Private siftDown
siftDown( startIdx?: number ) : void
Parameters
Default value startIdx: number = 0
Returns void
Private siftUp
siftUp( startIdx?: number ) : void
Parameters
Optional startIdx: number
Returns void
Legend
Module
Object literal
Variable
Function
Function with type parameter
Index signature
Type alias
Enumeration
Enumeration member
Property
Method
Interface
Interface with type parameter
Constructor
Property
Method
Index signature
Class
Class with type parameter
Constructor
Property
Method
Accessor
Index signature
Inherited constructor
Inherited property
Inherited method
Inherited accessor
Protected property
Protected method
Protected accessor
Private property
Private method
Private accessor
Static property
Static method
Heap (binary heap implementation)
In computer science, a heap is a specialized tree-based data structure which is essentially an almost complete tree that satisfies the heap property: in a max heap, for any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C. In a min heap, the key of P is less than or equal to the key of C.[2] The node at the "top" of the heap (with no parents) is called the root node.
Min heap
source: tutorialspoint.com
Max heap
source: tutorialspoint.com
Complexity
O(1)
O(n)
O(n)
O(n)
O(1)
O(log n)
O(log n)
O(log n)
O(1)
O(1)
O(n)
O(n)
Reference
import { BinaryHeap } from '@pencroff/ts-algorithms/dist/structure/heap'; const h = new BinaryHeap([1, 2, 3])