What’s inside.
Each chapter has a complete program to run, the time and memory cost, and exercises.
- 00
Install Python and prepare your workspace
Install Python 3.12 or newer, open a terminal and an editor, and run your first program.
- 01
Python foundations for DSA
The reliable core: names, numbers, functions, loops, lists, ranges and comparisons.
- 02
Lists, dicts and sets
The everyday containers, what each operation costs, and how to choose among them.
- 03
Strings and Unicode
Strings are immutable sequences of code points; count, compare and build text correctly.
- 04
Classes, references and copies
Build nodes from classes, and reason about names that share one mutable object.
- 05
Recursion
Base cases, smaller problems, and the recursion limit every Python call stack has.
- 06
- 07
- 08
Hash tables and Python dicts
How a key finds its slot, the hash and equality contract, and Counter and defaultdict.
See hash tables visualized - 09
Trees and binary search trees
Traverse a tree, insert and search a BST without recursion, and see why sorted input is slow.
See trees visualized - 10
Heaps and priority queues
Write a min-heap, then use heapq with tie-breakers so equal priorities never crash.
See heaps visualized - 11
Searching and sorting
Binary search with bisect, a stable merge sort, and sorted() with key functions.
- 12
Two pointers, sliding windows and prefix sums
Stop rescanning the same elements, and keep float totals from drifting.
- 13
Divide and conquer and backtracking
Combine answers to halves, or explore choices and undo each one cleanly.
- 14
- 15
Greedy algorithms
When the locally best choice is globally best, and how to test a greedy rule.
- 16
Dynamic programming
Define a state and a recurrence, then compare a table with functools.cache.
- 17
Mixed practice and projects
Choose a technique without a chapter title to help, and build a dependency planner.
Prefer another language? Go for DSA, JavaScript for DSA, Java for DSA or C++ for DSA.