DSA Study Center
Data structures and algorithms, one topic at a time.
A free study guide for coding interviews. 28 topics, each with how it works, how to spot it in an interview question, and classic problems worked through step by step: 56 in all. Every solution comes in 5 languages and is a complete program, run and checked against its expected output.
Start with Big-O & Complexity
Show code in
Foundations
How to measure an algorithm, and the structures everything else builds on.
Big-O & ComplexityMeasure how an algorithm's time and memory grow with its input, so you can compare approaches before you write them.Beginner2 worked problemsArrays & Hash MapsArrays look things up by position in O(1), and hash maps look them up by value in O(1) on average. Most O(n) solutions use one or both.Beginner2 worked problemsRecursionSolve a problem by calling the same function on a smaller piece of it, until the piece is small enough to answer directly.Beginner2 worked problems
Core Techniques
Patterns that turn a brute-force scan into a linear or logarithmic one.
Two PointersWalk two indices through an array at once to replace a nested loop with a single pass.Beginner2 worked problemsSliding WindowTrack one contiguous stretch of an array or string as it slides, updating it in O(1) per step instead of rescanning every subarray.Intermediate2 worked problemsPrefix SumsPrecompute running totals once so any range sum is a single subtraction, and count subarrays with a target sum in one pass.Beginner2 worked problemsBinary SearchHalve a sorted range on every step to find a value, a boundary, or the smallest answer that works, in O(log n) time.Beginner2 worked problemsSortingLearn how merge sort and quicksort trade off, what your library sort guarantees, and when a partition or a custom comparator is the whole answer.Intermediate2 worked problemsIntervalsSort ranges by their start so overlaps sit side by side, then merge, insert or count them in a single pass.Intermediate2 worked problemsGreedy AlgorithmsCommit to the choice that looks best at each step and never revisit it. Fast and simple, but only correct when you can prove that choice is safe.Intermediate2 worked problemsBit ManipulationWork on the binary form of integers directly: test and flip single bits, cancel pairs with XOR, and pack a small set into one number.Intermediate2 worked problems
Lists, Stacks & Queues
Sequential structures and the problems they make easy.
Linked ListsNodes chained by pointers: O(1) to insert or delete where you stand, O(n) to find anything. Master reversal, dummy heads and fast and slow pointers.Beginner2 worked problemsStacks & QueuesA stack hands back the newest item first and a queue the oldest, both in O(1). That order alone solves brackets, expression evaluation and BFS.Beginner2 worked problemsMonotonic StackKeep a stack in sorted order so every element finds its next greater or smaller neighbor in one O(n) pass.Intermediate2 worked problems
Trees & Heaps
Hierarchical structures for ordered data, prefixes and priorities.
Binary TreesNodes with up to two children: the four ways to traverse them, and the recursive pattern most tree problems reduce to.Beginner2 worked problemsBinary Search TreesA binary tree kept in order, so search, insert and delete follow one path down: O(log n) when balanced, O(n) when it degenerates.Intermediate2 worked problemsHeaps & Priority QueuesKeep the smallest or largest item on top with O(log n) inserts and removals: the tool for top-k, running medians and scheduling.Intermediate2 worked problemsTriesA tree of characters where every path from the root spells a prefix, so word and prefix lookups cost O(length of the word).Intermediate2 worked problemsSegment Trees & Fenwick TreesAnswer range queries on an array that keeps changing, with updates and queries both O(log n) instead of one of them costing O(n).Advanced2 worked problems
Graphs
Traversal, ordering, connectivity and shortest paths.
Graphs: BFS & DFSVisit everything reachable from a start node, ring by ring with a queue (BFS) or path by path with a stack (DFS), in O(V + E) time.Intermediate2 worked problemsTopological SortOrder the nodes of a directed graph so every edge points forward, or prove a cycle makes that impossible, using in-degree counts or DFS.Intermediate2 worked problemsUnion-FindTrack which items are connected as links arrive, merging groups and answering same-group questions in effectively constant time.Intermediate2 worked problemsShortest PathsFind the cheapest route through a weighted graph with BFS, Dijkstra or Bellman-Ford, depending on what the edge weights can be.Advanced2 worked problemsMinimum Spanning TreesConnect every vertex of a weighted graph at the lowest total cost, greedily, with Kruskal's edge-sorting or Prim's tree-growing.Advanced1 worked problem
Backtracking & Dynamic Programming
Exploring choices exhaustively, then reusing the answers to subproblems.
BacktrackingBuild answers one choice at a time: choose, explore, un-choose, and prune any branch that can't lead to a solution.Intermediate3 worked problemsDynamic Programming: 1DSolve each subproblem once: define a state, write a recurrence from the last decision, then fill a table from the smallest case up.Intermediate2 worked problemsDynamic Programming: Grids & StringsWhen a subproblem needs two numbers, like a grid cell or a pair of string prefixes, fill a 2D table where each cell builds on neighbors already done.Advanced2 worked problemsDynamic Programming: Knapsack & SubsequencesChoose items under a budget with a table indexed by capacity, and find the longest increasing subsequence from the best answer ending at each index.Advanced2 worked problems