Skip to content

About

Algorithms and data structures in TypeScript, one file per topic — following CLRS.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

OpenAlgorithms — TypeScript

CI

Algorithms and data structures in TypeScript, one file per topic. Part of the OpenAlgorithms organization.

Convention

  • One algorithm/structure per file: src/<category>/<name>.ts.
  • Every file has a co-located test: <name>.test.ts.
  • Every exported function/class carries a one-line Big-O comment above its definition (time and space, worst case unless noted).
  • No dependencies outside devDependencies — implementations are dependency-free by design.

Structure

src/
├── algorithms/
│   ├── sorting/            insertion, heap, quick, counting, radix, bucket
│   ├── searching/          linear, binary, randomized select, deterministic
│   │                       select (median-of-medians)
│   ├── divide-and-conquer/ maximum subarray, Strassen's matrix multiply
│   ├── dynamic-programming/ rod cutting, matrix chain, LCS, optimal BST
│   ├── greedy/             activity selection, Huffman coding
│   ├── graph/               BFS, DFS, topological sort, SCC (Kosaraju),
│   │                       Kruskal, Prim, Bellman-Ford, DAG shortest path,
│   │                       Dijkstra, Floyd-Warshall, Johnson,
│   │                       Ford-Fulkerson, bipartite matching, push-relabel
│   ├── string/             naive matcher, Rabin-Karp, Knuth-Morris-Pratt,
│   │                       finite automaton matcher
│   ├── math/                gcd, modular exponentiation, primality test
│   │                       (Miller-Rabin), RSA, FFT, LUP decomposition,
│   │                       matrix inversion, simplex (linear programming)
│   ├── geometry/            segment intersection, convex hull,
│   │                       closest pair of points
│   ├── np-complete/         subset sum, clique, vertex cover,
│   │                       Hamiltonian cycle, TSP (Held-Karp)
│   ├── approximation/       vertex cover, metric TSP, set cover,
│   │                       subset-sum FPTAS
│   └── concurrent/          multithreaded matrix multiply, multithreaded
│                           merge sort (real worker_threads, pooled)
└── data-structures/
    stack, queue, linked list, priority queue (binary heap), hash table,
    binary search tree, disjoint-set, red-black tree, B-tree, interval
    tree, order-statistic tree, dynamic table, Fibonacci heap,
    van Emde Boas tree

A note on concurrent/: it's the one category that doesn't fit the plain "one pure .ts file + test" shape. worker_threads needs an actual loadable script, not something the test runner transforms on the fly, so each algorithm there is a .ts orchestrator (pool creation, task splitting, merging results) paired with a plain .js worker entry file. The pooling logic itself lives in src/shared/workerPool.ts.

Commands

pnpm install
pnpm test         # vitest, all files
pnpm test:watch
pnpm typecheck     # tsc --noEmit
pnpm check         # biome check --fix

Status

Every category above is implemented and tested (303 tests, all green) — full coverage of the CLRS table of contents (Part VIII's math appendix aside, which is theory, not algorithms).

About

Algorithms and data structures in TypeScript, one file per topic — following CLRS.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages