A Go-first guide
Data Structures & Algorithms, in Go
The structures and techniques every engineer leans on — built and analyzed the Go way. From
Big-O to slices, hash tables, trees, graphs and dynamic programming, each page pairs a clear
mental model with idiomatic Go you can run right here and the costs you should know by heart.
Mark a topic “learned” on its page and watch the bars fill.
Skill map
Learned nodes light up — the glowing one is your next step. Click any node to jump in.
Complexity & Big-O
How to measure cost before you optimize — Big-O for time and space, amortized analysis, and reading the complexity of real Go code.
Linear Structures
The everyday building blocks — arrays and slices, strings, linked lists, stacks, queues and hash tables — and what each operation actually costs.
A Go slice is a view over a backing array — how the (ptr, len, cap) header, append, growth, copy and re-slicing actually behave, and the aliasing traps.
✦ Complete · ⏱ 4 min 3 · Beginner Linked ListsNodes joined by pointers — O(1) insert/delete at a known position, O(n) access; singly vs doubly linked, the reversal classic, and when a slice is the better choice.
✦ Complete · ⏱ 4 min 4 · Beginner Stacks & QueuesLIFO and FIFO with O(1) push and pop — a stack on a Go slice, the balanced-brackets classic, and the head-index trick that keeps a queue's dequeue cheap.
✦ Complete · ⏱ 3 min 5 · Beginner Hash TablesAverage O(1) lookup via hashing — how Go's built-in map works, collisions and load factor, the comma-ok idiom, and the ordering and nil-map gotchas.
✦ Complete · ⏱ 3 minTrees & Graphs
Hierarchical and networked data — binary search trees, heaps and priority queues, tries, and graph traversal with BFS, DFS and friends.
Nodes with up to two children — structure, depth vs height, the three DFS traversals (inorder, preorder, postorder), and level-order BFS with a queue.
✦ Complete · ⏱ 5 min 7 · Intermediate Binary Search TreesThe BST ordering invariant (left < node < right) gives O(h) search and insert, an inorder walk yields sorted order, and balance decides log n vs n.
✦ Complete · ⏱ 4 min 8 · Intermediate Heaps & Priority QueuesA binary heap packed in a slice — parent/child by index arithmetic, sift-up and sift-down in O(log n), and Go's container/heap to build a priority queue.
✦ Complete · ⏱ 5 min 9 · Intermediate TriesA prefix tree keyed by characters — Insert, Search and StartsWith in O(L) where L is the key length, the engine behind autocomplete and prefix queries.
✦ Complete · ⏱ 5 min 10 · Intermediate Graphs: BFS & DFSVertices joined by edges — adjacency lists, BFS for shortest hops, DFS for reachability and ordering, all O(V + E).
✦ Complete · ⏱ 5 min 10.5 · Intermediate Union-Find (Disjoint Set)Track which elements are connected — the disjoint-set forest, Find with path compression and Union by rank for near-O(1) operations, and its jobs: connected components, cycle detection, and Kruskal's MST.
✦ Complete · ⏱ 4 minAlgorithms & Patterns
The reusable techniques — sorting, binary search, two pointers and sliding window, recursion and backtracking, dynamic programming and greedy.
Find a value in a sorted slice in O(log n) by repeatedly halving the range — the correct loop, the off-by-one traps, and the stdlib helpers.
✦ Complete · ⏱ 3 min 12 · Intermediate SortingWhy comparison sorts can't beat O(n log n) — merge sort and quicksort by hand, then the one line you actually write in Go: slices.Sort.
✦ Complete · ⏱ 5 min 13 · Intermediate Two Pointers & Sliding WindowReplace nested loops with two indices that move with intent — converging pointers on sorted data and a sliding window for contiguous subarray and substring problems.
✦ Complete · ⏱ 5 min 14 · Intermediate Recursion & BacktrackingDefine a problem in terms of itself — base case plus recursive case, the call stack and its limits, and backtracking's choose / explore / un-choose loop.
✦ Complete · ⏱ 5 min 15 · Advanced Dynamic ProgrammingSolve problems with overlapping subproblems and optimal substructure — from exponential recursion to top-down memoization and bottom-up tabulation in Go.
✦ Complete · ⏱ 5 min 16 · Intermediate Greedy AlgorithmsMake the locally optimal choice and never look back — when greedy is provably correct, classic wins like interval scheduling, and where it fails.
✦ Complete · ⏱ 5 minRevise
🐹 Reach for the standard library first
In real Go you rarely hand-roll these — slices, maps, sort,
container/heap and container/list cover most needs. We build them from scratch
here so the costs and trade-offs are obvious; in production, prefer the battle-tested library version.