The Complete DSA with Python – Master Roadmap
What This Guide Is
A hands-on, no-nonsense guide to learning Data Structures and Algorithms using Python. The goal is to build genuine understanding, not to memorise solutions.
Every topic covers:
- The concept from first principles
- Python implementation with full code and complexity analysis
- The common patterns and techniques that come from that data structure
- Hands-on LeetCode problems tied directly to the topic
What You Need Before Starting
- Basic Python: variables, loops, conditionals, functions, lists, dicts
- No prior DSA knowledge needed. Everything else is explained from scratch.
The Roadmap
Part 1 – Foundation
| Blog | What You Will Learn |
|---|---|
| What is DSA and why do we learn it | What data structures and algorithms are, why they matter, how this guide is structured |
| How to use this guide and how to practice | Learning philosophy, how to approach problems, how to use LeetCode effectively |
| Python refresher for DSA | Lists, dicts, sets, tuples, list comprehensions, functions – the Python tools you will use constantly |
Part 2 – Complexity Analysis
Before touching any data structure, you need this vocabulary. Every single blog after this uses it.
| Blog | What You Will Learn |
|---|---|
| Time complexity | What it is, why it matters, intuition before formulas |
| Big O notation | O(1), O(log n), O(n), O(n log n), O(n^2) and beyond – with examples and intuition |
| Space complexity | Memory usage, in-place vs auxiliary space, how to analyse it |
| Analysing code | Step-by-step complexity analysis of real code snippets |
Part 3 – Data Structures
Each blog covers the concept, all operations with complexity, patterns that come from the structure, and LeetCode problems.
| Data Structure | Concepts Covered | Patterns Introduced |
|---|---|---|
| Arrays | Memory layout, Python lists, array module, NumPy intro, dynamic arrays, referential arrays, common operations and complexity | Two Pointers, Sliding Window, Prefix Sum, Binary Search on arrays |
| Strings | Immutability, string operations and complexity, string building efficiently | Sliding Window on strings, Two Pointers, Hashing for string problems |
| Linked Lists | Singly and Doubly Linked Lists, pointers, insert/delete/search/reverse, when to use over arrays | Fast and Slow Pointers, In-place Reversal |
| Stacks | Stack operations, Python list as stack, linked list implementation, the call stack, monotonic stacks | Monotonic Stack, state tracking with a stack |
| Queues and Deques | Queue and Deque, Python collections.deque, circular queue, when to use each | BFS with a queue, Sliding Window Maximum with deque |
| Hash Maps and Hash Sets | How hashing works, collision handling, Python dict and set internals, complexity of operations | Frequency counting, grouping, seen-so-far tracking |
| Trees | Binary Trees, BST, tree traversals (BFS and DFS), pre/in/post order, BST operations and complexity | Level Order BFS, DFS path problems |
| Heaps and Priority Queues | Min heap, max heap, heapify, Python heapq, heap operations and complexity | Top K Elements, Two Heaps |
| Graphs | Adjacency list and matrix, BFS and DFS, directed vs undirected, weighted vs unweighted, cyclic vs acyclic | Connected components, cycle detection, shortest path |
Part 4 – Algorithms
| Algorithm | Concepts Covered | Key Problems |
|---|---|---|
| Sorting | Bubble, Selection, Insertion (and why they are slow), Merge Sort, Quick Sort, Python’s built-in sort, when to use what | Sort Colors, Merge Intervals, Largest Number |
| Binary Search | Classic binary search, binary search on the answer, find leftmost/rightmost, rotated arrays | Binary Search, Search in Rotated Array, Find Minimum in Rotated Array |
| Recursion | How recursion works, the call stack, base cases, thinking recursively | Fibonacci, Generate Parentheses, Power function |
| Backtracking | Recursive exploration with pruning, decision trees as a mental model | Subsets, Permutations, N-Queens, Sudoku Solver |
| Dynamic Programming | Overlapping subproblems, optimal substructure, top-down vs bottom-up, 0/1 Knapsack, Unbounded Knapsack, LCS, Palindromes, DP on grids | Climbing Stairs, Coin Change, Longest Common Subsequence, Edit Distance |
| Greedy Algorithms | The greedy choice property, when greedy works and when it fails | Jump Game, Activity Selection |
| Graph Algorithms | Topological Sort, Dijkstra, Bellman-Ford, Kruskal, Prim | Course Schedule, Shortest Path, Cheapest Flights Within K Stops |
Part 5 – Advanced Data Structures
| Data Structure | Concepts Covered | Key Problems |
|---|---|---|
| Tries | What a Trie is, insert, search, startsWith, when to use a Trie | Implement Trie, Word Search II, Replace Words |
| Union-Find (DSU) | Find, Union, path compression, union by rank, cycle detection | Number of Connected Components, Redundant Connection, Accounts Merge |
| Segment Trees | Range queries, point updates, build, update, query, lazy propagation | Range Sum Query, Range Minimum Query |
| Bit Manipulation | Bitwise operators, common bit tricks, when to reach for bit manipulation | Single Number, Counting Bits, Reverse Bits, Power of Two |
Part 6 – Pattern Playbook (Reference)
This is a consolidated reference of every pattern covered across the guide. You learn each pattern inside its topic. This section is for review, revision, and recognising patterns when you encounter new problems.
| Pattern | Where You First Learn It | What It Solves |
|---|---|---|
| Two Pointers | Arrays | Pair problems, in-place operations, reducing O(n^2) to O(n) |
| Sliding Window | Arrays, Strings | Subarray and substring problems with a constraint |
| Prefix Sum | Arrays | Range sum queries, subarray sum problems |
| Binary Search (and variants) | Binary Search | Search problems, optimisation problems phrased as search |
| Fast and Slow Pointers | Linked Lists | Cycle detection, finding midpoints |
| In-place Linked List Reversal | Linked Lists | Reversing parts of a list without extra space |
| Monotonic Stack | Stacks | Next greater/smaller element problems |
| BFS (Level Order) | Trees, Graphs | Shortest path in unweighted graphs, level-by-level tree problems |
| DFS | Trees, Graphs | Path problems, connected components, cycle detection |
| Two Heaps | Heaps | Problems needing both the max of one half and min of the other |
| Top K Elements | Heaps | Finding K largest, smallest, or most frequent elements |
| Frequency Counting / Hashing | Hash Maps | Anagram, duplicate, grouping problems |
| Subsets and Combinations | Backtracking | Generating all subsets, combinations, permutations |
| Dynamic Programming patterns | Dynamic Programming | Knapsack, LCS, palindromes, grid DP |
| Topological Sort | Graph Algorithms | Ordering tasks with dependencies |
| Union-Find applications | Union-Find | Connected components, dynamic connectivity |
| Bitwise XOR | Bit Manipulation | Finding missing or non-duplicate numbers efficiently |
How We Will Build This
One blog at a time, in order. Each blog is self-contained and ends with a summary, key takeaways, practice problems, and a pointer to the next topic.
Start here: What is DSA and why do we learn it
Additional Resources
| Resource | Description | Link |
|---|---|---|
| Codeverra DSA Sheet | A curated list of 100+ DSA problems organised by topic, with completion tracking. Use this to track your progress as you work through the guide. | Open Sheet |
| Solutions Notebook | Google Colab notebook with fully explained Python solutions for all problems covered in this guide. | Link will be added |
