Kodewick
Start learning →
Data structures and algorithms · Python

Data Structures and Algorithms in Python

Build data structures by hand in Python: nodes, references, resizing, hashing, every step drawn for you. Then learn the standard library tools (deque, heapq, bisect, lru_cache) and why they are fast. Each chapter ends with the patterns interviews ask for.

Start with lesson 1 →52 lessons · about 16 hours · free · runs in your browser
  1. Part 1Getting started: how fastCounting steps, Big O, where log n comes from, and what each built-in list, dict and set operation costs.4 lessons · 1 h
    1. Lesson 1Counting the steps15 minStart
    2. Lesson 2Big O: O(1), O(n), O(n²)16 minStart
    3. Lesson 3Where log n comes from16 minStart
    4. Lesson 4What built-in operations cost: list, dict, set20 minStart
  2. Part 2Names, lists and linked listsVariables are labels on objects: aliases and copies; a list is a row of references: indexing, inserting, deleting, growing; linked lists by hand, nodes, inserting and deleting, doubly linked lists and an LRU cache.8 lessons · 2.5 h
    1. Lesson 5Names and objects: references, aliases and copies17 minStart
    2. Lesson 6Inside a list: a row of references18 minStart
    3. Lesson 7Inserting and deleting in a list18 minStart
    4. Lesson 8Arrays that grow: resizing by hand19 minStart
    5. Lesson 9Linked lists: nodes and next15 minStart
    6. Lesson 10Inserting and deleting in a linked list16 minStart
    7. Lesson 11Doubly linked lists, circular lists and an LRU cache18 minStart
    8. Lesson 12Patterns: lists and linked lists20 minStart
  3. Part 3Stacks and queuesA list as a stack, matching brackets, postfix expressions; why a queue wants deque, a circular queue by hand, monotonic stacks and sliding windows.5 lessons · 1.5 h
    1. Lesson 13Stacks: last in, first out14 minStart
    2. Lesson 14Matching brackets12 minStart
    3. Lesson 15Evaluating expressions: postfix16 minStart
    4. Lesson 16Queues: deque and circular queues15 minStart
    5. Lesson 17Patterns: stacks and queues20 minStart
  4. Part 4Hash tables: dict and setHash functions and __hash__, open addressing (what CPython's dict does), chaining and resizing, and two-sum, Counter and grouping problems.4 lessons · 1.5 h
    1. Lesson 18Hash functions and __hash__18 minStart
    2. Lesson 19Open addressing: how dict does it20 minStart
    3. Lesson 20Separate chaining18 minStart
    4. Lesson 21Patterns: hash tables20 minStart
  5. Part 5Trees and heapsBinary trees and recursion, four traversals, rebuilding a tree, binary search trees, a heap by hand and then heapq, heap sort and top-k, Huffman coding, every step drawn on the tree.8 lessons · 2.5 h
    1. Lesson 22Binary trees and recursion15 minStart
    2. Lesson 23Four ways to walk a binary tree18 minStart
    3. Lesson 24Rebuilding a tree from its traversals18 minStart
    4. Lesson 25Binary search trees18 minStart
    5. Lesson 26Heaps and heapq18 minStart
    6. Lesson 27Heap sort and top-k18 minStart
    7. Lesson 28Huffman trees and Huffman codes18 minStart
    8. Lesson 29Patterns: trees20 minStart
  6. Part 6GraphsAdjacency matrices and lists, BFS and DFS, topological sort, Dijkstra with heapq, Kruskal (union-find) and Prim, every step drawn on the graph.7 lessons · 2 h
    1. Lesson 30Storing a graph: adjacency matrix and list16 minStart
    2. Lesson 31Breadth-first search (BFS)17 minStart
    3. Lesson 32Depth-first search (DFS)17 minStart
    4. Lesson 33Topological sort16 minStart
    5. Lesson 34Shortest paths: Dijkstra18 minStart
    6. Lesson 35Minimum spanning trees: Kruskal and Prim18 minStart
    7. Lesson 36Patterns: graphs22 minStart
  7. Part 7SearchingBinary search and its bounds, bisect, balanced trees (AVL rotations), and binary search on the answer.4 lessons · 1 h
    1. Lesson 37Binary search16 minStart
    2. Lesson 38Binary search bounds and bisect17 minStart
    3. Lesson 39Balanced trees: AVL20 minStart
    4. Lesson 40Patterns: searching20 minStart
  8. Part 8SortingBubble, selection, insertion, Shell, merge, quick, counting and radix sort, each run for real with its comparisons counted; then sorted() keys, stability and Timsort.6 lessons · 2 h
    1. Lesson 41Bubble sort and selection sort16 minStart
    2. Lesson 42Insertion sort and Shell sort16 minStart
    3. Lesson 43Merge sort24 minStart
    4. Lesson 44Quicksort24 minStart
    5. Lesson 45Counting sort and radix sort22 minStart
    6. Lesson 46Patterns: sorting and sorted()28 minStart
  9. Part 9Algorithm designRecursion and divide and conquer, backtracking, greedy, dynamic programming (from recursion to lru_cache to a table) and knapsack problems.6 lessons · 2.5 h
    1. Lesson 47Recursion and divide and conquer22 minStart
    2. Lesson 48Backtracking22 minStart
    3. Lesson 49Greedy algorithms20 minStart
    4. Lesson 50Dynamic programming22 minStart
    5. Lesson 51Knapsack problems24 minStart
    6. Lesson 52Patterns: algorithm design26 minStart

Questions

Is it really free?

Yes. Every lesson, example and exercise is free, with no sign-up.

Do I need to know Python first?

A little: variables, loops, functions, lists and dicts, ideally classes too. If not, start with our Python course.

How is it different from the C edition?

The same chapters, taught the Python way: no pointers or malloc, more on references, how list and dict work inside, and the standard library tools.

Is there a C++ edition?

Yes: Data Structures and Algorithms in C++, each structure by hand first, then with the STL (/en/learn/dsa-cpp/).

Where is my progress kept?

In this browser, with no account.