The DSA path
Data structures and algorithms in Python, in the order that works. Start at Level 0 if lists and dictionaries still feel new. Otherwise begin at Level 1.
You can also browse every topic on the algorithms hub.
Level 0
Warm-up: the tools Python gives you
Lists, dictionaries and the collections module. You use these in every later lesson.
- Lists, Tuples, Dicts & SetsLists, tuples, dicts and sets. Picking the right one is most of what makes code fast and readable.65 min
- Dictionaries, Part 1: Lookup and How It WorksDictionaries are the most-used data structure in Python — every object, every module namespace, every JSON response from an API is a dict under the hood.40 min
- Dictionaries, Part 2: Comprehensions, JSON and MergingComprehensions, nested dicts and JSON, why dicts keep their order, and the merge operators.40 min
- The collections Module: Python's Supercharged Data StructuresCounter, defaultdict, deque, namedtuple — these are the data structures that separate hobbyist scripts from production code.65 min
Level 1
Foundations
What an algorithm costs, then stacks, queues, recursion, linked lists, array patterns and hash tables.
- Algorithms and Data Structures: Start HereWhat a data structure and an algorithm are, what n and log n mean, how to read Big-O in five lines, a map of the lessons ahead, and a one-page cost cheat sheet for list, dict, set, deque, heap and sorted.45 min
- Big-O and searchingMeasure how running time grows with the input, name the growth as Big-O, search a sorted list with binary search and bisect, and spot where that cost hides in ML code.40 min
- Stacks and queuesStacks and queues: last in first out and first in first out, with deque, circular queues, the monotonic stack, and real uses such as undo, rate limiting and breadth-first search.50 min
- Recursion & Dynamic Programming, Part 1: The IdeaThe call stack, base and recursive cases, why naive recursion goes exponential, and the two ways out of it — memoization and tabulation — plus the 5-question DP framework.45 min
- Linked Lists, Part 1: Singly Linked ListsBuild a singly linked list from node objects, reverse it, find its middle and detect a cycle, then measure it against list and deque to see when it is the wrong choice.50 min
- Linked Lists, Part 2: Doubly Linked, Merge & LRU CacheBuild on Part 1's singly linked list: doubly linked lists with prev/next pointers, merging two sorted lists, full LRU cache, and recursive reversal.35 min
- Array Patterns: Two Pointers, Sliding Window and Prefix SumsThree habits that turn nested loops over a list or string into one pass: two pointers from the ends or in the same direction, a sliding window of fixed or variable size, and prefix sums with a dict, with a rule for choosing between them.55 min
- Build a Hash TableBuild a hash table from scratch: a hash function, collisions, separate chaining, open addressing with tombstones and resizing, see why doubling gives amortized O(1), then compare it with CPython's dict and choose between a dict, a set and a sorted list.55 min
Level 2
Core
Sorting, binary search patterns, trees, heaps, graphs and backtracking: the tools most interview and real-world problems rest on.
- Sorting AlgorithmsSort by hand with bubble, selection and insertion sort, then build merge sort and quick sort, see why no comparison sort beats n log n, break that limit with counting and radix sort, and learn what Python's sorted does.60 min
- Binary Search PatternsWrite binary search with an invariant so it never goes off by one, find the first and last copy of a value with lower and upper bound, search a rotated list, search on the answer with a yes or no test, search real numbers, and find a peak.55 min
- Trees & BST, Part 1: Binary Trees & TraversalsTrees from first principles — terminology, the TreeNode class, BST insert/search, and all four traversals (BFS, inorder, preorder, postorder) recursively and iteratively.65 min
- Trees & BST, Part 2: Balanced Trees & TrieBST deletion with all three cases, the famous cross-level validation bug, self-balancing AVL/Red-Black trees, Tries for autocomplete, and expression trees evaluated by postorder.35 min
- HeapsA heap keeps the smallest item one step away without sorting anything else: the array layout, heapq, the max-heap trick, building one from scratch, and the classic top-K problems.55 min
- GraphsGraph vocabulary, adjacency lists, matrices and edge lists, BFS and DFS and which question each one answers, the fewest-edges route, and counting connected components. Cheapest routes and Union-Find have their own lessons.40 min
- Backtracking: Try, Check, UndoSolve subsets, permutations, combinations, combination sum, N-Queens and word search with one choose, explore, un-choose template, cut dead branches early, count the work honestly, and know when dynamic programming is the better tool.55 min
Level 3
Advanced
Dynamic programming patterns, shortest paths, Union-Find, greedy algorithms, divide and conquer, rigorous asymptotics and bit manipulation.
- Dynamic Programming, Part 2: The Classic ProblemsFive classic problems (coin change, knapsack, longest common subsequence, longest increasing subsequence and edit distance) worked with the 5-question framework, plus when to pick memoization or tabulation.55 min
- DP Patterns, Part 2: Grids, Intervals, Bitmasks and TreesA repeatable method for designing a dynamic program, then grid DP, longest increasing subsequence in O(n log n), interval DP, bitmask DP for a small travelling salesman, DP on trees, rolling rows, rebuilding the real answer, and how to choose between DP, greedy, backtracking and plain recursion.60 min
- Shortest Paths: Dijkstra, Bellman-Ford, A* and MoreFind the cheapest route through a graph with BFS, Dijkstra and a heap, topological sort and DAG paths, Bellman-Ford for negative edges, Floyd-Warshall for all pairs, 0-1 and multi-source BFS, and A* on a grid, then pick the right one from a table.60 min
- Union-Find and Minimum Spanning TreesKeep track of which items are in the same group with a parent array, make it almost O(1) with path compression and union by rank, use it for dynamic components, cycles, islands and merged accounts, then build the cheapest network with Kruskal and Prim.60 min
- Greedy Algorithms: Take the Best Now, Then Prove It Is SafeLearn what makes a greedy rule correct, prove one with the exchange and stays-ahead arguments, solve interval, Huffman, jump game, gas station and meeting room problems, see greedy fail on knapsack and coins, and decide between greedy and dynamic programming.60 min
- Divide and Conquer: Split, Solve, CombineSplit a problem into smaller copies of itself, write its cost as a recurrence, solve it with a recursion tree and the master theorem, then use the idea for fast powers, maximum subarray, counting inversions, quickselect, Karatsuba multiplication and the closest pair of points.60 min
- Asymptotics and amortized analysisDefine O, Omega, Theta and little-o with the c and n0 picture, prove bounds by choosing c and n0, solve recurrences by substitution, count space including the recursion stack, and analyse amortized cost with the aggregate, accounting and potential methods.60 min
- Bit Manipulation: Working With Individual BitsRead numbers in binary, use & | ^ ~ << >> with hand traces, understand Python's unlimited integers and negatives, master the test, set, clear and toggle tricks and x & (x - 1), count bits, use XOR, enumerate subsets with a bitmask, and see bit packing, quantization and bitsets at work.55 min
Level 4
Expert
Balanced trees, range queries, string algorithms, probabilistic structures, advanced graphs, storage structures, vector search, NP-hardness and how CPython builds its containers, then a playbook for choosing the technique.
- Balanced Trees: AVL, Red-Black and B-TreesWhy a plain search tree collapses on sorted input, how AVL rotations keep the height logarithmic with a proof, the red-black idea, and why databases use wide B-tree nodes to cut disk reads.60 min
- Range Queries: Prefix Sums, Sparse Tables, Fenwick and Segment TreesAnswer many range sum and range minimum questions while the data changes: prefix sums and why updates break them, the sparse table, the Fenwick tree and its lowbit trick, the segment tree with lazy propagation, a sqrt decomposition note, and a decision table.60 min
- String Algorithms: KMP, Rolling Hash, Tries and Suffix ArraysSearch text for a pattern without re-reading it: the naive worst case, KMP and its prefix table, Rabin-Karp and rolling hashes, the Z-algorithm and Horspool skipping, Aho-Corasick for many words, suffix arrays, palindromes, and a pointer to edit distance.60 min
- Probabilistic Structures: Bloom Filters, Count-Min, HyperLogLog, Sampling and Consistent HashingTrade a small, controlled chance of error for a huge saving in memory: Bloom filters with their false-positive formula and sizing, count-min sketches, HyperLogLog, reservoir sampling and consistent hashing with virtual nodes, all built with replayable hashes.60 min
- Advanced Graphs: Components, Bridges, Matching and Max-FlowFind strongly connected components with Kosaraju, bridges and articulation points with low-links, test for two-colorability, match items with augmenting paths, and compute max-flow and min-cut with Edmonds-Karp, with the cost and the reason for each.60 min
- Storage Structures: B+ Trees, Skip Lists and LSM TreesWhy disks change the rules, how a B+ tree turns a billion keys into a handful of block reads, how a skip list gets log n from coin flips, and how a log-structured merge tree with a write-ahead log, Bloom filters and compaction trades read cost for fast writes.60 min
- Vector Search: Nearest Neighbors at ScaleFind the closest vectors to a query: distance and cosine similarity, exact search and its O(n d) cost, the curse of dimensionality, k-d trees, random-hyperplane hashing, clustering lists, navigable graphs (HNSW), quantization, and how to measure recall against speed.60 min
- NP-Hardness and Approximation: When Exact Is Too SlowTell easy problems from hard ones: P, NP and reductions in plain words, the classic NP-complete problems, pseudo-polynomial subset sum and knapsack, then the three ways out: exact exponential search, approximation with proofs, and heuristics.60 min
- CPython Container Internals: list, dict, set, heapq, sorted and bisectSee how CPython builds list, tuple, dict, set, deque, heapq, sorted and bisect: over-allocation, the hash and equality contract, a heap stored in a list, runs and galloping in Timsort, and what interning promises, each shown by counting.60 min
- How CPython Works: Bytecode, Objects, the Cycle Collector and the GILRead the bytecode CPython runs with dis, explain what a Python object is, find reference cycles, and say what the GIL and the free-threaded build change.65 min
- The Problem-Solving Playbook: How to Choose the TechniqueRead the constraints to find the target cost, follow a six-step method and a decision flow, match signals to every technique in Part 10, debug with a tiny counter and a stress test, avoid the common traps, and finish with five mixed problems where you must name the technique first.60 min