A comprehensive book on data structures and algorithms, with tested TypeScript implementations. Covers the core curriculum of an undergraduate algorithms course - from sorting and searching through graph algorithms, dynamic programming, and computational complexity.
- Read online at https://amoilanen.github.io/Algorithms-with-Typescript/
- PDF https://amoilanen.github.io/Algorithms-with-Typescript/algorithms-with-typescript.pdf
The book is organized into six parts across 22 chapters:
| Part | Chapters | Topics |
|---|---|---|
| I. Foundations | 1--3 | Algorithms, analysis, recursion, divide-and-conquer |
| II. Sorting and Selection | 4--6 | Elementary sorts, efficient sorts, linear-time sorts, selection |
| III. Data Structures | 7--11 | Lists, stacks, queues, hash tables, trees, BSTs, heaps |
| IV. Graph Algorithms | 12--15 | Traversal, shortest paths, MSTs, network flow |
| V. Design Techniques | 16--17 | Dynamic programming, greedy algorithms |
| VI. Advanced Topics | 18--22 | Union-find, tries, string matching, NP-completeness, approximation |
Every algorithm discussed in the book is implemented in TypeScript under src/ and tested under tests/.
- Node.js >= 18
- Pandoc >= 3.0 (for PDF build)
- A LaTeX distribution with XeLaTeX, or Tectonic (for PDF build)
- DejaVu fonts (for PDF build)
- mdBook (for website build)
# Install dependencies
npm install
# Run the test suite
npm test
# Type-check all implementations
npm run typecheck
# Lint and format
npm run lint
npm run format:checkRequires Pandoc and a LaTeX engine (XeLaTeX or Tectonic):
# Arch Linux
sudo pacman -S pandoc texlive-xetex texlive-latexextra texlive-fontsrecommended ttf-dejavu
# Debian / Ubuntu
sudo apt install pandoc texlive-xetex texlive-latex-extra texlive-fonts-recommended fonts-dejavu
# macOS (with Homebrew)
brew install pandoc
brew install --cask mactex
brew install font-dejavu
# Build the PDF
npm run build:pdfThe PDF is written to dist/pdf/algorithms-with-typescript.pdf.
Requires mdBook:
# Install mdBook
cargo install mdbook
# or download a binary from https://github.com/rust-lang/mdBook/releases
# Build the static site
npm run build:web
# Preview locally
mdbook serve book --openThe website is written to dist/web/.
When editing chapters locally, use mdbook serve to get a live-reloading preview — the browser refreshes automatically every time you save a file under book/chapters/:
mdbook serve book --openThis starts a local server at http://localhost:3000 (by default) and watches book/chapters/ for changes. Edit any Markdown file in your editor, save it, and the page updates instantly in the browser — no manual rebuild needed.
Tip: If port 3000 is already in use, pick another one with
mdbook serve book --open --port 3001.
The website is automatically deployed to GitHub Pages on every push to master via the GitHub Actions workflow in .github/workflows/deploy.yml.
src/ TypeScript implementations, organized by chapter
tests/ Vitest test suite, mirroring src/ structure
book/
chapters/ Markdown source for all 22 chapters, preface, notation, and bibliography
metadata.yaml Pandoc/LaTeX configuration for PDF
book.toml mdBook configuration for the website
scripts/
build-pdf.sh PDF build script (Pandoc + XeLaTeX/Tectonic)
build-web.sh Website build script (mdBook)
| Script | Description |
|---|---|
npm test |
Run the full test suite |
npm run test:watch |
Run tests in watch mode |
npm run typecheck |
Type-check with tsc --noEmit |
npm run lint |
Lint with ESLint |
npm run lint:fix |
Auto-fix lint issues |
npm run format |
Format with Prettier |
npm run format:check |
Check formatting |
npm run build:pdf |
Build the PDF |
npm run build:web |
Build the website |
MIT