Skip to content

Data Structures Overview

The shared package contains reusable lists, queues, stacks, heaps, trees, and math/comparator utilities. Two recent additions are highlighted below:

  • BinaryHeap – array-backed heap optimized for fast insert/extract and used by PriorityQueue.
  • BinarySearchTree – pointer-based search tree that keeps data ordered while enabling in-order traversal and range queries.

Complexity: BinaryHeap vs BinarySearchTree

StructureInsertLookupExtract min/maxTraversalNotes
BinaryHeapO(log n)O(n) (needs scan)O(log n)O(n) (via snapshot)Great for schedulers/priority queues. Comparator defines min/max behavior.
BinarySearchTreeO(log n) average (O(n) worst)O(log n) averageO(log n)O(n) with chosen orderMaintains sorted order and exposes traversals + min/max.
ts
const heap = new BinaryHeap(createComparator('priority'))
heap.insert({ priority: 10 })
const top = heap.extractMin()

const tree = new BinarySearchTree(createComparator('id'))
;['b', 'a', 'c'].forEach(id => tree.insert({ id }))
const ordered = tree.traverse() // in-order

Other structures (quick recap)

  • Lists: flexible sequences (List, LinkedList, etc.) with slicing/splicing helpers.
  • Queues: FIFO options (Queue, LinkedQueue, PriorityQueue, Dequeue).
  • Stacks: LIFO via Stack and LinkedStack.
  • Heaps: BinaryHeap for general use, FibonacciHeap for algorithms requiring amortized decreaseKey.
  • Sorting: QuickSort/HeapSort utilities operating on ICollection implementations.
  • Math & utils: Point, Ordering, createComparator, printHeap, and core interfaces.

Notes

  • Read more in Heaps and Trees.
  • Lists, queues, stacks, and sorting helpers each have dedicated pages linked from the sidebar.
  • All structures rely on the shared Comparator helpers for deterministic ordering.

Built with VitePress – Released under the MIT License.