Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Heap

Heap Data structure

Hierarchy

  • Heap

Constructors

constructor

  • Parameters

    Returns Heap

Properties

compare

compare: Comparator

heapContainer

heapContainer: any[]

Methods

add

  • add(item: any): Heap
  • Parameters

    • item: any

    Returns Heap

find

  • find(item: any, comparator?: Comparator): number[]
  • Parameters

    • item: any

      item to find

    • comparator: Comparator = ...

      A comparator instance

    Returns number[]

    array of indices of the item in the heap

getLeftChildIndex

  • getLeftChildIndex(parentIndex: number): number
  • Parameters

    • parentIndex: number

      Parent's index

    Returns number

    Index of the left child

getParentIndex

  • getParentIndex(childIndex: number): number
  • Parameters

    • childIndex: number

      Index of the node

    Returns number

    Parent's index

getRightChildIndex

  • getRightChildIndex(parentIndex: number): number
  • Parameters

    • parentIndex: number

      Parent's index

    Returns number

    Index of the right child

hasLeftChild

  • hasLeftChild(parentIndex: number): boolean
  • Parameters

    • parentIndex: number

    Returns boolean

hasParent

  • hasParent(childIndex: number): boolean
  • Parameters

    • childIndex: number

      Index of the node

    Returns boolean

hasRightChild

  • hasRightChild(parentIndex: number): boolean
  • Parameters

    • parentIndex: number

      Parent's index

    Returns boolean

heapifyDown

  • heapifyDown(startIndex?: number): void
  • Compare the parent with both of it's children and swap it with the appropriate child (smaller child for MinHeap and bigger child for MaxHeap). Do the same for next children after swap.

    Parameters

    • Optional startIndex: number

      Index to start heapify process from

    Returns void

heapifyUp

  • heapifyUp(startIndex?: number): void
  • Take the last item (last in the container array or bottom left in the heap) and lift it up until its in the correct position with respect to its parent

    Parameters

    • Optional startIndex: number

      Index to start heapify process from

    Returns void

isEmpty

  • isEmpty(): boolean
  • Returns boolean

Abstract isPairInCorrectOrder

  • isPairInCorrectOrder(parent: any, child: any): boolean
  • MaxHeap: Parent must be greater than or equal to the child node MinHeap: Parent must be less than or equal to the child node

    Parameters

    • parent: any

      Parent Node

    • child: any

      Child Node

    Returns boolean

leftChild

  • leftChild(parentIndex: number): any
  • Parameters

    • parentIndex: number

      Parent's index

    Returns any

parent

  • parent(childIndex: number): any
  • Parameters

    • childIndex: number

      Index of the node

    Returns any

peak

  • peak(): any
  • Get the root node without modifying the heap

    Returns any

poll

  • poll(): any
  • Remove the root node

    Returns any

remove

  • Parameters

    • item: any

      Item to remove

    • comparator: Comparator = ...

      A comparator Instance

    Returns Heap

rightChild

  • rightChild(parentIndex: number): any
  • Parameters

    • parentIndex: number

      Parent's index

    Returns any

swap

  • swap(index1: number, index2: number): void
  • Parameters

    • index1: number

      Index of the first item

    • index2: number

      Index of the second item

    Returns void

toString

  • toString(): string
  • Returns string