Back

Show HN: Algorithms and Data Structures in TypeScript – Free Book (~400 Pages)

35 points2 hoursamoilanen.github.io

I started writing this book 10 years ago in JavaScript, got through a few chapters (asymptotic notation, basic techniques, start of sorting), and then abandoned it.

Recently I picked it back up, converted everything to TypeScript, and used AI (Zenflow [1] + Claude Opus 4.6) to complete the remaining chapters. I provided the structure, direction, and initial chapters; the AI generated the bulk of the remaining content under a spec-driven workflow.

The book covers roughly a first 1-2 year CS curriculum: sorting, dynamic programming, graph algorithms, trees, heaps, hash tables, and more. All code is executable, typed with generics/interfaces, and covered with tests.

I've thoroughly reviewed several chapters (sorting, DP, graphs) and done a high-level pass on the rest. Currently in beta — corrections and contributions are welcome.

MIT licensed. Inspired by Wirth's "Algorithms and Data Structures", SICP, and CLRS.

Code and tests: https://github.com/amoilanen/Algorithms-with-Typescript

[1] https://zencoder.ai/zenflow

gausswho24 minutes ago

this is well structured and put together. i would think it serves as a good base for refreshing oneself on the fundamentals. and it has a satisfying bend towards being both concise and thorough.

BloodAndCode49 minutes ago

this is great timing for me — i actually have an algorithms & data structures course this semester. seeing implementations in typescript instead of the usual pseudo-code or java/python is really nice. makes it much easier to actually run the code and play with the ideas while learning. curious — did writing this in typescript change how you approached any of the classic structures? some of them feel a bit awkward with generics in certain languages.

jsontwikkeling27 minutes ago

Great to hear that. I actually think TypeScript is very fit for the purpose, even better than Python (lacks types) or Java (bulkier).

Type signatures document contracts directly:

  export function rabinKarp(text: string, pattern: string): number[]
Clear that it takes two strings and returns match positions. No separate explanation needed.

Interfaces model return types and ADTs cleanly:

  export interface ShortestPathResult<T> {
    dist: Map<T, number>;
    parent: Map<T, T | undefined>;
  }

  export function dijkstra<T>(graph: Graph<T>, source: T): ShortestPathResult<T>
It's also lightweight, flexible, has familiar C-like syntax, and unlike pseudocode — you can actually run everything.

Re: generics feeling awkward — in TypeScript they feel pretty natural. The type inference helps a lot, you rarely need to spell out type parameters at call sites.

BloodAndCode8 minutes ago

that makes sense. the type signatures as documentation point is actually really nice — being able to see the contract immediately is a big plus compared to a lot of pseudocode examples in textbooks. i also like the idea that everything is runnable. a lot of algorithm books show the idea but you rarely get something you can directly execute and experiment with.

will definitely try some of the implementations while studying this semester.

Copyrightest30 minutes ago

[dead]