Skip to content

Algorithm ​

Import algorithm data structures, direct functions, and study results from tyrus:algorithm. The module provides native, high-performance implementations of classic data structures together with deterministic algorithm metrics. All handle types are generic except FenwickTree, SegmentTree, SparseTable, SegmentTreeLazy, BitSet, BloomFilter, and Trie. Native handles are released automatically when their binding goes out of scope.

AlgorithmDescriptionPage
UnionFind<T>Disjoint set (union-find) with path compression and union by rankUnionFind
BinaryHeap<T>Binary max-heap priority queueBinaryHeap
BinomialHeap<T>Binomial max-heap priority queue with O(log n) meldBinomialHeap
Counter<T>Frequency counter with insertion-order preservationCounter
Deque<T>Double-ended queueDeque
FenwickTreeFenwick tree (binary indexed tree) for prefix sumsFenwickTree
SegmentTreeSegment tree for range queries and point updatesSegmentTree
SparseTableImmutable RMQ table for range minimum queriesSparseTable
SegmentTreeLazySegment tree for range queries and range additionsSegmentTreeLazy
BitSetCompact bit set with set-theoretic operationsBitSet
BloomFilterProbabilistic set membership with a configurable false-positive rateBloomFilter
Graph<N, W>Directed weighted graph with automatic node creation and DOT renderingGraph
bfs / bfsInfoBreadth-first traversal or its study resultBFS
dfs / dfsInfoIterative depth-first traversal or its study resultDFS
iddfs / iddfsInfoIterative-deepening traversal or its study resultIDDFS
dijkstra / dijkstraInfoNon-negative shortest path or its study resultDijkstra
aStar / aStarInfoHeuristic shortest path or its study resultA*
bellmanFord / bellmanFordInfoNegative-weight shortest paths or their study resultBellman-Ford
floydWarshall / floydWarshallInfoDense all-pairs shortest paths or their study resultFloyd-Warshall
spfa / spfaInfoQueue-based shortest paths or their study resultSPFA
johnson / johnsonInfoSparse all-pairs shortest paths or their study resultJohnson
kruskalMinimum spanning forest with disjoint setskruskal
primMinimum spanning tree with a priority queueprim
boruvkaMinimum spanning forest for dense graphsboruvka
steinerTreeWeighted terminal connection treesteinerTree
edmondsKarpMaximum flow with breadth-first augmenting pathsedmondsKarp
dinicMaximum flow with level graphsdinic
pushRelabelMaximum flow with vertex heightspushRelabel
minCutMinimum cut from maximum flowminCut
minCostMaxFlowMinimum-cost maximum flowminCostMaxFlow
topologicalSortKahnTopological ordering with indegreestopologicalSortKahn
topologicalSortDfsTopological ordering with DFStopologicalSortDfs
tarjanSccStrongly connected components with TarjantarjanScc
kosarajuSccStrongly connected components with KosarajukosarajuScc
fleuryEulerianEulerian path with FleuryfleuryEulerian
hierholzerEulerianEulerian path with HierholzerhierholzerEulerian
findBridgesBridge detectionfindBridges
findCutVerticesArticulation point detectionfindCutVertices
biconnectedComponentsBiconnected component decompositionbiconnectedComponents
edmondsBlossomMaximum general-graph matchingedmondsBlossom
hungarianMinimum-cost assignmenthungarian
mergeSort / mergeSortInfoStable merge sort and its study resultmergeSort
quickSort / quickSortInfoAverage-case quick sort or its study resultquickSort
heapSort / heapSortInfoHeap sort or its study resultheapSort
countingSort / countingSortInfoCounting sort or its study resultcountingSort
radixSort / radixSortInfoRadix sort or its study resultradixSort
bucketSort / bucketSortInfoBucket sort or its study resultbucketSort
timSort / timSortInfoHybrid comparison sort or its study resulttimSort
insertionSort / insertionSortInfoInsertion sort or its study resultinsertionSort
shellSort / shellSortInfoShell sort or its study resultshellSort
selectionSort / selectionSortInfoSelection sort or its study resultselectionSort
bubbleSort / bubbleSortInfoImmediate bubble sort or study result with semantic metricsBubble sort
shakerSort / shakerSortInfoBidirectional bubble sort or its study resultshakerSort
quickselectSelect the k-th smallest value without fully sorting the arrayquickselect
binarySearchBinary search over an ascending integer arraybinarySearch
interpolationSearchDistribution-aware search over a uniformly distributed integer arrayinterpolationSearch
exponentialSearchSearch an ascending integer array by exponentially expanding its rangeexponentialSearch
kmpSearchExact substring search with prefix preprocessingkmpSearch
zAlgorithmPrefix-match preprocessing for a stringzAlgorithm
rabinKarpSubstring search with a rolling hashrabinKarp
boyerMooreSubstring search with the bad-character ruleboyerMoore
ahoCorasickMultiple-pattern search returning pattern matchesahoCorasick
levenshteinEdit distance between two stringslevenshtein
TriePrefix tree for string wordsTrie
suffixArrayLexicographic suffix array construction for stringssuffixArray
SuffixTreeSuffix tree built with Ukkonen's algorithm, with lexicographic suffix array extractionsuffixTreeUkkonen
LcaLowest common ancestor tables over a tree with O(log n) querieslcaBinaryLifting
HldHeavy-light decomposition with O(log n) chain path queriesheavyLightDecomposition
CentroidCentroid decomposition with O(log n) centroid-tree depthcentroidDecomposition
LinkedList<T>Singly linked listLinkedList
DoubleLinkedList<T>Doubly linked listDoubleLinkedList
AvlTree<T>Self-balancing AVL tree (ordered set)AvlTree
RedBlackTree<T>Self-balancing red-black tree (ordered set)RedBlackTree
SplayTree<T>Self-adjusting splay tree (ordered set)SplayTree
Treap<T>Randomized treap (ordered set)Treap
SortedSet<T>Ordered set backed by a balanced binary search treeSortedSet
SkipList<T>Randomized skip list (ordered set)SkipList
SortedMap<K, V>Ordered key → value map backed by a balanced binary search treeSortedMap