Data Structures & Algorithms
A full, language-neutral course in data structures and algorithms with Python examples. Every topic pairs theory and complexity analysis with your own implementation and a set of problems, from arrays and hashing through trees, graphs and dynamic programming to segment trees, ending with a personal algorithms library and timed problem sets.
What you will be able to do
- Analyse the time and space complexity of any algorithm you write or read
- Implement core data structures from scratch and know their trade-offs
- Apply sorting, searching, tree and graph algorithms to unfamiliar problems
- Recognise greedy, dynamic programming and backtracking problems and derive solutions
- Solve medium-level coding problems within a timed session and explain them clearly
Roadmap
Bar length shows each module's share of study time.
- 114h5 topics
Complexity analysis & math basics
The language for comparing algorithms, plus the math it rests on.
Show topicsNot startedDescribe an algorithm's growth rate with the correct asymptotic notation.
- Define upper, lower and tight bounds
- Drop constants and lower-order terms
- Rank common growth rates
- Separate best, average and worst case
Derive the running time of loops, nested loops and simple recursions by inspection.
- Count work in sequential and nested loops
- Spot logarithmic halving loops
- Write recurrences for recursive functions
- Apply the master theorem to common recurrences
Explain why some operations are cheap on average and measure the extra memory an algorithm uses.
- Use the aggregate method for amortised cost
- Count auxiliary space versus input space
- Include recursion stack depth in space
- Measure real runtimes with timeit
Use logarithms, series, modular arithmetic and basic counting in algorithm analysis.
- Work with logarithms and powers of two
- Evaluate arithmetic and geometric series
- Compute with modular arithmetic
- Count permutations and combinations
- Implement fast exponentiation
Pick the right built-in container for a task knowing the complexity of its operations.
- Review list, dict and set operation costs
- Use deque, Counter and defaultdict
- Use heapq and bisect modules
- Write quick tests with pytest
- 212h4 topics
Arrays & strings
Contiguous memory, resizing and the most common interview data type.
Show topicsNot startedExplain why array indexing is O(1) and insertion in the middle is O(n).
- Compute element addresses from the index
- Insert and delete by shifting elements
- Explain cache locality benefits
- Work with 2D arrays as row-major
Implement a growable array and prove append is amortised O(1).
- Track size versus capacity
- Grow by doubling and copy
- Implement append, pop, get and set
- Prove amortised O(1) append
Manipulate strings efficiently and solve anagram, palindrome and parsing problems.
- Explain string immutability and its costs
- Build strings with join, not +=
- Count characters with arrays or Counter
- Solve palindrome and anagram problems
- Parse tokens from a string
Answer range-sum queries in O(1) and rearrange arrays in place without extra memory.
- Build 1D prefix sum arrays
- Answer range queries in constant time
- Use 2D prefix sums for submatrices
- Reverse and rotate arrays in place
- Partition an array in one pass
Module resources:Python data structures ↗ - 314h 30m5 topics
Linked lists, stacks, queues & deques
Pointer-based sequences and the LIFO/FIFO structures built on them.
Show topicsNot startedImplement a singly linked list and reverse, merge and split lists with pointer manipulation.
- Implement node and list classes
- Insert and delete at head and tail
- Reverse a list iteratively and recursively
- Use a dummy head node
- Merge two sorted lists
Use doubly linked and circular lists and detect cycles with fast and slow pointers.
- Implement a doubly linked list with sentinels
- Remove a node in O(1)
- Detect cycles with Floyd's algorithm
- Find the middle with fast and slow pointers
Implement a stack and use it for bracket matching, expression evaluation and undo history.
- Implement a stack on a list
- Match brackets with a stack
- Evaluate postfix expressions
- Replace recursion with an explicit stack
Implement a queue with a circular buffer and choose between queue and deque for a problem.
- Implement a ring buffer queue
- Explain why list.pop(0) is O(n)
- Use collections.deque at both ends
- Build a sliding window maximum with a deque
Solve next-greater-element and histogram problems in O(n) with a monotonic stack.
- Maintain an increasing or decreasing stack
- Find the next greater element
- Solve daily temperatures
- Find the largest rectangle in a histogram
Module resources:VisuAlgo: linked list, stack, queue ↗ - 410h3 topics
Hashing
Constant-time lookup and the collisions that make it interesting.
Show topicsNot started- Hash functionsLearn visually 2h 30m
Explain what makes a good hash function and why keys must be immutable.
- Map keys to bucket indexes
- Explain uniformity and determinism
- Hash strings with polynomial rolling hashes
- Explain why mutable keys break hashing
Implement a hash map with collision handling and resizing.
- Implement separate chaining
- Implement linear probing with tombstones
- Track load factor and rehash
- Compare average and worst-case costs
Turn O(n^2) brute-force searches into O(n) solutions using hash maps and sets.
- Solve two-sum with a complement map
- Group items by a computed key
- Count frequencies and find top items
- Use prefix sums with a hash map
- Detect duplicates with a set
Module resources:VisuAlgo: hash table ↗ - 519h7 topics
Recursion, sorting & searching
Think recursively, divide and conquer, then sort and search efficiently.
Show topicsNot startedWrite correct recursive functions with clear base cases and trace them on the call stack.
- Identify base case and recursive case
- Trace calls on the call stack
- Draw recursion trees
- Know Python's recursion limit
- Convert simple recursion to iteration
Split a problem into independent subproblems and combine their answers efficiently.
- Identify divide, conquer and combine steps
- Solve maximum subarray with divide and conquer
- Analyse with recurrences
- Count inversions during merging
Implement the quadratic sorts and explain stability and when insertion sort wins.
- Implement bubble and selection sort
- Implement insertion sort
- Define stable and in-place sorting
- Explain insertion sort on nearly sorted data
- Merge sortLearn visually 2h 30m
Implement merge sort and explain its guaranteed O(n log n) time and O(n) extra space.
- Split recursively to single elements
- Merge two sorted halves
- Analyse the recursion tree
- Implement a bottom-up variant
Implement quicksort with a good pivot strategy and find the k-th element with quickselect.
- Partition with Lomuto and Hoare schemes
- Choose random or median-of-three pivots
- Explain the O(n^2) worst case
- Find the k-th smallest with quickselect
Sort integers in linear time and use Python's sort with keys correctly.
- Implement counting sort
- Implement LSD radix sort
- Explain the comparison sort lower bound
- Sort with key functions and Timsort
Write bug-free binary search and apply it to monotonic answer spaces.
- Write binary search with clear invariants
- Find first and last occurrence
- Search a rotated sorted array
- Binary search on the answer space
- Use the bisect module
Module resources:VisuAlgo: sorting ↗ - 618h 30m6 topics
Trees, heaps & tries
Hierarchical structures for ordered data, priorities and prefixes.
Show topicsNot startedTraverse a binary tree in pre-, in-, post- and level order, recursively and iteratively.
- Learn tree vocabulary: root, leaf, height
- Implement pre-, in- and post-order
- Implement level-order with a queue
- Write iterative traversals with a stack
- Compute height and diameter
Implement BST search, insert and delete and explain why balance matters.
- Implement search and insert
- Delete nodes with zero, one, two children
- Find successor and predecessor
- Validate a BST
- Show degeneration into a linked list
Explain how rotations keep AVL and red-black trees at O(log n) height.
- Perform left and right rotations
- Track AVL balance factors
- State the red-black tree rules
- Compare AVL and red-black trade-offs
- Know where balanced trees appear in libraries
Implement an array-based min-heap with sift-up, sift-down and O(n) heapify.
- Map tree positions to array indexes
- Implement push with sift-up
- Implement pop with sift-down
- Build a heap in O(n)
Use heaps for top-k, merging sorted lists and scheduling, and implement heap sort.
- Use heapq for push and pop
- Find top-k elements with a size-k heap
- Merge k sorted lists
- Track a running median with two heaps
- Implement heap sort
Implement a trie and use it for prefix search and autocomplete.
- Implement insert and search
- Answer startsWith prefix queries
- Collect words for autocomplete
- Compare tries with hash sets
- 713h 30m5 topics
Graphs: representations & traversal
Model relationships and explore them systematically.
Show topicsNot startedStore directed, undirected and weighted graphs as adjacency lists, matrices and edge lists.
- Learn vertices, edges, degree and paths
- Build adjacency lists with dicts
- Compare adjacency matrix and list costs
- Treat grids as implicit graphs
Use BFS to find shortest paths in unweighted graphs and grids.
- Implement BFS with a queue and visited set
- Reconstruct paths from parent links
- Run multi-source BFS
- Solve grid shortest-path problems
Use DFS to count components, detect cycles and flood-fill grids.
- Implement recursive and iterative DFS
- Count connected components
- Detect cycles with three-colour marking
- Flood-fill islands in a grid
Order tasks in a DAG with Kahn's algorithm or DFS and detect impossible orderings.
- Define DAGs and dependency order
- Implement Kahn's algorithm with in-degrees
- Implement DFS post-order topological sort
- Detect cycles in course schedules
Implement union-find with path compression and union by rank for near-constant connectivity queries.
- Implement find and union
- Add path compression
- Add union by rank or size
- Count components dynamically
- 89h 30m3 topics
Shortest paths & minimum spanning trees
Weighted graph algorithms for routes and cheap networks.
Show topicsNot startedFind single-source shortest paths with non-negative weights using a heap.
- Relax edges and track distances
- Implement Dijkstra with heapq
- Skip stale heap entries
- Explain why negative weights break it
Handle negative edge weights, detect negative cycles and compute all-pairs shortest paths.
- Relax all edges V-1 times
- Detect negative cycles
- Solve limited-stops shortest paths
- Implement Floyd-Warshall for all pairs
Build a minimum spanning tree with Kruskal's and Prim's algorithms.
- State the cut property
- Implement Kruskal with union-find
- Implement Prim with a heap
- Choose between them by graph density
- 921h 30m6 topics
Greedy algorithms & dynamic programming
Optimisation by local choice, or by reusing overlapping subproblems.
Show topicsNot startedRecognise problems with the greedy-choice property and justify a greedy solution.
- Schedule intervals by earliest end time
- Merge overlapping intervals
- Prove greedy with an exchange argument
- Find counterexamples where greedy fails
- Solve jump game and gas station
Turn a recursive solution into memoised and bottom-up DP and solve classic 1D problems.
- Spot overlapping subproblems and optimal substructure
- Memoise with a dict or lru_cache
- Convert to bottom-up tabulation
- Solve climbing stairs and house robber
- Reduce space to O(1)
Define 2D states and fill grid and string DP tables in the right order.
- Count unique grid paths
- Find minimum path sum
- Compute edit distance
- Choose table fill order
- Reduce a 2D table to one row
Solve 0/1 and unbounded knapsack and map subset-sum and coin-change problems onto them.
- Define the 0/1 knapsack state
- Iterate capacity backwards for 1D DP
- Solve unbounded knapsack and coin change
- Solve subset sum and partition
- LIS & LCSLearn visually 3h 30m
Compute longest increasing and longest common subsequences and reconstruct the answers.
- Solve LIS in O(n^2) with DP
- Solve LIS in O(n log n) with patience
- Solve LCS with a 2D table
- Reconstruct the subsequence from the table
Solve problems over subarrays by iterating interval length, such as burst balloons and matrix chain.
- Define dp over intervals i to j
- Iterate by increasing interval length
- Solve matrix chain multiplication
- Solve palindromic substring problems
Module resources:NeetCode roadmap ↗ - 109h 30m3 topics
Backtracking & bit manipulation
Systematic search with pruning, and tricks with binary representations.
Show topicsNot startedGenerate subsets, permutations and combinations with a choose-explore-unchoose template.
- Learn the choose, explore, unchoose template
- Generate all subsets
- Generate all permutations
- Generate combinations and combination sums
- Skip duplicates in sorted input
Solve N-Queens, Sudoku and word search efficiently by pruning invalid branches early.
- Solve N-Queens with column and diagonal sets
- Solve word search on a grid
- Write a Sudoku solver
- Prune branches with constraint checks
Use bitwise operators to test, set and count bits and represent sets as bitmasks.
- Use AND, OR, XOR, NOT and shifts
- Test, set and clear individual bits
- Count bits and isolate the lowest bit
- Find the single number with XOR
- Enumerate subsets with bitmasks
Module resources:LeetCode problem set ↗ - 1113h4 topics
Advanced patterns & range structures
Linear-time array patterns and logarithmic range queries.
Show topicsNot startedReplace nested loops with converging or same-direction pointers on sorted arrays and lists.
- Use converging pointers on sorted arrays
- Solve two-sum II and three-sum
- Remove duplicates in place
- Solve container with most water
Solve substring and subarray problems in O(n) with fixed and variable windows.
- Use fixed-size windows for averages
- Grow and shrink variable windows
- Find the longest substring without repeats
- Find the minimum window substring
Implement a Fenwick tree for prefix sums with point updates in O(log n).
- Explain the lowbit index trick
- Implement point update
- Implement prefix and range queries
- Count inversions with a Fenwick tree
Implement a segment tree for range sum, min or max queries with point updates.
- Build the tree recursively
- Answer range queries
- Apply point updates
- Generalise to min, max and gcd
- Understand lazy propagation for range updates
- 1222h3 topics
Capstone: library & timed problem sets
Consolidate everything into your own tested library and timed practice.
Show topicsNot startedPublish a Python package of your own data structures and algorithms with tests and benchmarks.
- Implement core structures in one package
- Write pytest tests including edge cases
- Benchmark against built-ins with timeit
- Document complexity for every function
- Publish the repo with a README
Solve mixed-topic medium problems within 30 to 45 minutes each using a repeatable method.
- Use a clarify, plan, code, test method
- Solve mixed sets under a timer
- Explain the approach out loud
- Log mistakes and pattern misses
- Revisit failed problems after a week
Map any new problem to a known pattern and keep every topic fresh with spaced review.
- Build a pattern-to-problem cheat sheet
- Re-solve one problem per pattern
- Schedule spaced review of weak topics