Back to both DSA books

Data structures
and algorithms
in JavaScript.

JavaScript for DSA, complete edition
JavaScript for DSA book cover

Learn the algorithms with the language you already write every day.

Every example is a complete Node.js program with no framework, no npm packages and no TypeScript. The book covers the classic data structures and algorithms, and the JavaScript details that trip people up in interviews and real code: references, UTF-16 strings, number precision and the hidden cost of some array methods.

PDF, 60 pages, 1.0 MB. Free with Google sign-in.

Written for JavaScript, not translated into it.

What’s inside.

Each chapter has a complete program to run, the time and memory cost, and exercises.

  1. Install Node.js and prepare your workspace

    Set up a current LTS release of Node.js, an editor and a terminal.

  2. JavaScript foundations for DSA

    The reliable core: values, variables, functions, loops, arrays and comparisons.

  3. Arrays, maps and sets

    The everyday storage tools, and how to choose among them.

  4. Strings and Unicode

    Why string indexes are UTF-16 code units, and how to handle characters correctly.

  5. Objects and references

    Group fields into nodes and records, and reason about shared, mutable objects.

  6. Recursion

    Base cases, smaller instances, and the stack space every call uses.

  7. Stacks and queues

    The two ordering rules behind DFS, BFS, bracket checking and scheduling.

  8. Linked lists

    Nodes joined by references, and the cost of reaching an element.

  9. Hash tables and JavaScript maps

    Find a value by key without scanning, using Map for counting and membership.

  10. Trees and binary search trees

    Traverse a tree, insert and search a BST, and see why “binary” does not mean fast.

  11. Heaps and priority queues

    Serve the most urgent item first with a compact binary heap.

  12. Searching and sorting

    Linear and binary search, a predictable merge sort, and JavaScript’s default sort trap.

  13. Two pointers, sliding windows and prefix sums

    Reuse work across an array, with half-open ranges and safe sums.

  14. Divide and conquer and backtracking

    Combine answers to subproblems, or explore and undo choices.

  15. Graph traversal

    Represent a graph with Map and Set, run BFS and DFS, and recover a shortest path.

  16. Greedy algorithms

    Prove when a locally attractive choice is globally optimal.

  17. Dynamic programming

    Turn repeated subproblems into a table with explicit states and transitions.

  18. Mixed practice and projects

    Choose a technique without a chapter title to help, and build a small dependency planner.