Data Structures and Algorithms
Begin with arrays, linked lists, stacks, queues, trees, and graphs. Each lesson shows how the data is laid out, how common operations work, and what those operations cost.
The algorithm lessons build on those structures. Sorting explains how order is created; searching explains how ordered data lets a program discard work.
Start with the foundations
Learn how to describe an operation, estimate its running time, and choose storage that matches the work a program performs.
- Time and Space Complexitylesson
Compare constant, logarithmic, linear, and quadratic growth before choosing an implementation.
- Recursionlesson
Break a problem into smaller calls and understand the call stack and base case.
- Data Structureslesson
How values are arranged, accessed, inserted, removed, and updated.
Linear data structures
These structures keep values in a sequence. The important difference is how each one finds, inserts, and removes an item.
Arrays
Contiguous storage: indexing is constant time, but inserting in the middle is not.
- Arrayslesson
Contiguous memory, indexes, traversal, insertion, deletion, and dynamic resizing.
- Static vs Dynamic Arrayslesson
Understand the difference between fixed-size memory blocks and auto-expanding lists.
- Multidimensional Arrayslesson
Learn how grids and matrices are mapped onto linear computer memory.
- Prefix Sumslesson
Query the sum of any subarray in constant time using a precomputed array.
- Difference Arrayslesson
Apply massive overlapping range updates in constant time per update.
- Sparse Arrayslesson
Store massive arrays efficiently when most of their elements are zero or empty.
Linked lists
Order comes from references between nodes, so inserting is cheap but indexing is not.
- Linked Listslesson
Nodes, references, traversal, insertion, deletion, and reversal.
- Singly Linked Listslesson
Master the mechanics of one-way node traversal and the fast/slow pointer technique.
- Doubly Linked Listslesson
Leverage backward pointers for O(1) deletions and complex caching structures.
- Circular Linked Listslesson
Build a continuous ring of nodes where the tail connects back to the head.
- Skip Listslesson
Achieve O(log N) search times in a linked list using multiple layers of express lanes.
Stacks
Last in, first out. The restriction is what makes execution order useful.
Queues
First in, first out, plus the ring buffers and double-ended variants built on it.
- Queueslesson
The First-In-First-Out processing model and its critical role in breadth-first search.
- Circular Queueslesson
Use modulo arithmetic to build efficient, fixed-size ring buffers.
- Dequeslesson
Double-ended queues allow insertion and deletion at both the front and rear.
- Monotonic Queueslesson
Combine a deque with a monotonic invariant to conquer sliding window problems.
Strings
A string is an array of characters, with its own scanning and matching techniques.
Trees, graphs, and indexed structures
Use these when relationships branch, connect in many directions, or need faster lookup than a simple scan.
Trees
Hierarchies that branch, and the balancing rules that keep them shallow.
- Treeslesson
Roots, children, depth, traversal, binary search trees, and balanced trees.
- Binary Treeslesson
Understand the foundations of binary trees, nodes, leaves, and hierarchical data.
- Binary Search Treeslesson
Learn how the BST property enables fast lookups and sorted retrievals.
- Tree Traversalslesson
Explore Pre-order, In-order, Post-order, and Level-order traversal strategies.
- Lowest Common Ancestorlesson
Find the deepest node that is an ancestor of two specific targets.
- Tree Diameter and Heightlesson
Calculate the longest path between any two nodes in a tree structure.
Balanced and disk-based trees
Self-balancing variants that bound height, and the wide trees built for disk.
Indexed trees
Trees over an array that answer range queries and updates in logarithmic time.
Heaps and priority queues
Keep the smallest or largest item reachable while values keep arriving.
Hashing and prefix structures
Constant-time lookup by key, and trees keyed on shared prefixes.
- Hash Tableslesson
Keys, hash functions, collisions, sets, maps, and constant-time lookup.
- Trieslesson
Store words by shared prefixes for lookup and autocomplete.
- Trie Operations and Applicationslesson
Build efficient prefix trees for autocomplete and string dictionaries.
- Suffix Arrayslesson
Sort all suffixes of a string to solve complex substring problems efficiently.
- Suffix Treeslesson
Compress all suffixes of a string into a powerful, navigatable Trie.
- Bloom Filterslesson
Trade absolute certainty for immense space savings in set membership queries.
Graphs
Vertices and edges, and the connectivity structures built on them.
Core algorithms
Algorithms transform or inspect the structures above. Each group below shares one idea: creating order, discarding work, scanning with indexes, or arithmetic on whole numbers.
Sorting
Ordering makes every later lookup cheaper. These lessons compare how each algorithm moves values, what it costs, and when it is the right choice.
- Sorting Algorithmslesson
Compare every sort on time, space, stability, and when to reach for it.
- Bubble Sortlesson
Swap adjacent pairs each pass, and stop early when a pass makes no swap.
- Selection Sortlesson
Scan the unsorted tail for its minimum, then place it in one swap.
- Insertion Sortlesson
Grow a sorted prefix by shifting larger values right — fast on nearly sorted data.
- Merge Sortlesson
Split to single values, then merge sorted runs in guaranteed O(n log n).
- Quick Sortlesson
Partition around a pivot, and see why pivot choice decides the worst case.
- Heap Sortlesson
Build a max-heap in place, then repeatedly extract the root.
- Counting Sortlesson
Count occurrences instead of comparing, for small integer ranges.
- Radix Sortlesson
Sort digit by digit with a stable pass per position.
- Bucket Sortlesson
Spread values across buckets, sort each, then concatenate.
- Shell Sortlesson
Insertion sort over shrinking gaps, moving values far in one step.
Searching
Once data is ordered, a search can discard half the remaining candidates at every step instead of scanning them all.
Scanning with indexes
One pass, two moving positions. These techniques avoid rescanning a sequence that has already been examined.
String matching
Find a pattern inside a longer text without restarting the comparison after every mismatch.
Number theory
Arithmetic on whole numbers: divisibility, primes, modular results, and the identities that keep them fast.
String algorithms
Linear-time scanning of text: match a pattern, measure palindromes, or compare substrings in constant time.
- Z-Algorithmlesson
Compute, for every position, how far the string matches its own prefix — in one linear pass.
- Manacher's Algorithmlesson
Find every palindromic radius in linear time by mirroring inside the rightmost known palindrome.
- String Hashinglesson
Reduce a substring comparison to one arithmetic difference, and handle collisions honestly.
Numbers and counting
The arithmetic a competitive or interview problem assumes you already know.
- Modular Arithmeticlesson
Work in congruence classes, and invert a multiplication when division is unavailable.
- Combinatorics Basicslesson
Count arrangements and selections by argument rather than enumeration, using Pascal's rule.
- Matrix Exponentiationlesson
Advance a linear recurrence in logarithmic time by squaring its transition matrix.
- Randomized Algorithmslesson
Use randomness for correctness in expectation — shuffling, sampling, and why the range must shrink.
Problem-solving methods
These methods apply when a direct scan is not enough: the problem has overlapping subproblems, a safe local choice, or a structure of connections to explore.
Recursion and reuse
Split a problem into smaller versions of itself, avoid solving the same version twice, and undo a choice that leads nowhere.
- Divide and Conquerlesson
Split independent subproblems, solve recursively, and analyze the combine recurrence.
- Dynamic Programminglesson
Save answers to repeated subproblems and build the final answer from them.
- Memoizationlesson
Turn repeated recursive states into explicit cache hits and misses.
- Backtrackinglesson
Choose, explore, undo, and continue through combinations and arrangements.
Making local choices
Commit to the best option available right now, and justify why that choice cannot be regretted later.
Graph traversal
Visit every reachable vertex in a defined order. That order is what makes the rest of graph work possible.
- Advanced Graph Algorithmslesson
Shortest paths, topological ordering, minimum spanning trees, and connectivity.
- Breadth-First Searchlesson
Explore a graph level by level with a queue and visited set.
- Depth-First Searchlesson
Grow and unwind the active call stack while exploring a graph.
- Topological Sortlesson
Drain in-degrees with Kahn's algorithm or reverse DFS finish order.
- Cycle Detectionlesson
Use directed colors or undirected union-find to expose cycle witnesses.
Shortest paths and spanning trees
Weighted graphs: reach every vertex as cheaply as possible, or connect them all for the least total cost.
Bitwise techniques
Treat an integer as a row of flags and let single hardware instructions do the set operations.
Advanced dynamic programming
Once a state is more than one index, the shape of that state is the whole design decision.
- Two-Dimensional Dynamic Programminglesson
Fill a table whose state is a pair of coordinates, in an order that respects dependencies.
- Bitmask Dynamic Programminglesson
Let an integer's bits name a visited subset, and iterate over subsets instead of positions.
- Tree Dynamic Programminglesson
Combine independent child answers in one post-order pass, with rerooting when every root matters.
- Digit Dynamic Programminglesson
Count numbers by fixing digits left to right, carrying only whether the prefix is still tight.
Flows, colouring, and heuristics
Graph problems that are not shortest paths: how much can flow, how few colours are needed, and how to search with an estimate.
- A* Searchlesson
Order the frontier by cost so far plus an admissible estimate of the cost remaining.
- Network Flow and Maximum Flowlesson
Augment along residual paths, and see why the reverse edge is what makes it correct.
- Graph Colouringlesson
Assign the smallest safe colour greedily, and understand why that is a bound, not the optimum.
- Johnson's Algorithmlesson
Reweight edges with vertex potentials so Dijkstra runs safely on a graph with negative weights.