Back to both DSA books

Data structures
and algorithms
in Go.

Go for DSA, complete edition
Go for DSA book cover

Learn the algorithms and the language together, in Go’s own style.

Most DSA material is written for Java or Python and translated. This book starts from Go: slices, maps, structs and pointers, runes and the standard library. Every chapter has a complete program you can run, the cost of each approach in time and memory, and exercises with solutions.

PDF, 64 pages, 1.3 MB. Free with Google sign-in.

Written for Go, not translated into it.

What’s inside.

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

  1. Install Go and prepare your workspace

    Set up Go, a terminal and an editor, and run your first program.

  2. Go foundations for DSA

    Enough Go for your first algorithms: variables, conditions, loops, functions and slices.

  3. Maps and sets

    Count values, test membership, and replace a repeated scan with a lookup.

  4. Strings, bytes and runes

    Pick bytes, runes or characters so text algorithms count the right thing.

  5. Structs and pointers

    Model linked nodes and see the difference between a struct value and a pointer.

  6. Recursion

    Find the smaller problem and the stopping condition, and count the stack space.

  7. Stacks and queues

    Newest first or oldest first, built on slices, with the memory trap in slice queues.

  8. Linked lists

    Build a singly linked list, trace pointer changes, and know when a list is worth it.

  9. Hash tables and Go maps

    How a key finds its slot, what happens on a collision, and what a map lookup really costs.

  10. Trees and binary search trees

    Tree vocabulary, three depth-first traversals, and when a BST is actually fast.

  11. Heaps and priority queues

    Implement a min-heap and recognise Go’s container/heap interface.

  12. Searching and sorting

    Binary search without off-by-one mistakes, and what sorting costs.

  13. Two pointers, sliding windows and prefix sums

    Three ways to stop rescanning the same elements, and when each one applies.

  14. Divide and conquer and backtracking

    Split a problem into smaller ones, and search choices while undoing each cleanly.

  15. Graph traversal with BFS and DFS

    Represent a graph, visit each vertex once, and find shortest paths with BFS.

  16. Greedy algorithms and their limits

    When locally best choices give the best answer, and how to justify the rule.

  17. Dynamic programming: state, recurrence and cost

    Define a state, write the recurrence and base cases, and compute the cost.

  18. Mixed practice and small Go projects

    Choose a technique without a chapter title to help, and build a small route finder.