Data Structures in Python

Master data structures in Python: Big-O, lists, dicts and sets, deques and heaps, trees and tries, graphs, union-find, LRU caches and interview patterns.

Start course →

What you'll learn

  • Analyse time and space complexity and understand Python's object model, references and copies.
  • Use lists, tuples, dataclasses, strings and bytes efficiently, knowing the cost of each operation.
  • Apply dicts, sets and the collections module for lookups, counting, grouping and layered data.
  • Implement and use stacks, queues, linked lists, heaps, binary trees, BSTs and tries.
  • Represent graphs and apply BFS, DFS, Dijkstra, topological sort and union-find to real problems.
  • Build caches and custom containers, save memory at scale, and solve problems with common interview patterns.

Syllabus

Foundations: Complexity and Python's Object Model

  1. Why Data Structures and Big-O Matter
  2. Python's Object Model: References, Mutability and Copies
  3. Measuring Time and Memory

Sequences: Lists, Tuples and Strings

  1. Lists: Python's Dynamic Array
  2. Tuples, namedtuple and dataclasses
  3. Strings, Bytes and Efficient Text Building

Hash Tables: dict, set and collections

  1. Dictionaries: Hash Tables in Practice
  2. Sets and Frozensets
  3. Counter, defaultdict, OrderedDict and ChainMap

Stacks, Queues, Linked Lists and Heaps

  1. Stacks and Queues with list and deque
  2. Linked Lists
  3. Heaps and Priority Queues

Trees and Tries

  1. Binary Trees and Traversals
  2. Binary Search Trees and Sorted Collections
  3. Tries for Prefix Search

Graphs

  1. Representing Graphs
  2. Breadth-First and Depth-First Search
  3. Dijkstra's Algorithm and Topological Sort

Advanced Structures and Memory

  1. Union-Find (Disjoint Set Union)
  2. Caches: LRU with OrderedDict and functools
  3. Memory-Efficient Structures: slots, array, generators and NumPy

Choosing Structures, Custom Containers, Patterns and Revision

  1. Choosing the Right Data Structure
  2. Building Custom Containers
  3. Interview Patterns: Two Pointers, Sliding Windows, Prefix Sums and Monotonic Stacks
  4. Revision and Interview Questions