|
| 1 | +# Python Time & Space Complexity |
| 2 | + |
| 3 | +> Comprehensive documentation of time and space complexity for Python built-in operations and standard library modules. |
| 4 | + |
| 5 | +This site documents the Big-O time and space complexity of Python operations across built-in types, built-in functions, and standard library modules. It covers CPython 3.9–3.14, with notes on PyPy, Jython, and IronPython. |
| 6 | + |
| 7 | +## Built-in Types |
| 8 | + |
| 9 | +- [Lists](https://pythoncomplexity.com/builtins/list/): Time and space complexity for list operations (append, insert, pop, sort, slicing, etc.) |
| 10 | +- [Dictionaries](https://pythoncomplexity.com/builtins/dict/): Complexity for dict operations (lookup, insert, delete, iteration) |
| 11 | +- [Sets](https://pythoncomplexity.com/builtins/set/): Complexity for set operations (membership, union, intersection, difference) |
| 12 | +- [Tuples](https://pythoncomplexity.com/builtins/tuple/): Complexity for tuple operations (indexing, slicing, membership) |
| 13 | +- [Strings](https://pythoncomplexity.com/builtins/str/): Complexity for string operations (find, replace, split, join, slicing) |
| 14 | +- [Bytes & Bytearray](https://pythoncomplexity.com/builtins/bytes/): Complexity for bytes and bytearray operations |
| 15 | +- [Frozenset](https://pythoncomplexity.com/builtins/frozenset/): Complexity for frozenset operations |
| 16 | +- [Range](https://pythoncomplexity.com/builtins/range/): Complexity for range operations (O(1) membership testing) |
| 17 | +- [Integer](https://pythoncomplexity.com/builtins/int/): Complexity for arbitrary-precision integer arithmetic |
| 18 | +- [Float](https://pythoncomplexity.com/builtins/float/): Complexity for floating-point operations |
| 19 | +- [Boolean](https://pythoncomplexity.com/builtins/bool/): Complexity for boolean operations |
| 20 | + |
| 21 | +## Built-in Functions |
| 22 | + |
| 23 | +- [len()](https://pythoncomplexity.com/builtins/len/): O(1) for built-in types |
| 24 | +- [sorted()](https://pythoncomplexity.com/builtins/sorted/): O(n log n) Timsort |
| 25 | +- [max()](https://pythoncomplexity.com/builtins/max/): O(n) linear scan |
| 26 | +- [min()](https://pythoncomplexity.com/builtins/min/): O(n) linear scan |
| 27 | +- [sum()](https://pythoncomplexity.com/builtins/sum/): O(n) accumulation |
| 28 | +- [map()](https://pythoncomplexity.com/builtins/map/): Lazy O(1) per element |
| 29 | +- [filter()](https://pythoncomplexity.com/builtins/filter/): Lazy O(1) per element |
| 30 | +- [zip()](https://pythoncomplexity.com/builtins/zip/): Lazy O(1) per element |
| 31 | +- [enumerate()](https://pythoncomplexity.com/builtins/enumerate/): Lazy O(1) per element |
| 32 | +- [reversed()](https://pythoncomplexity.com/builtins/reversed/): O(1) iterator creation |
| 33 | +- [all()](https://pythoncomplexity.com/builtins/all/): O(n) short-circuit |
| 34 | +- [any()](https://pythoncomplexity.com/builtins/any/): O(n) short-circuit |
| 35 | +- [hash()](https://pythoncomplexity.com/builtins/hash/): Varies by type |
| 36 | +- [isinstance()](https://pythoncomplexity.com/builtins/isinstance/): O(n) MRO lookup |
| 37 | + |
| 38 | +## Standard Library (Key Modules) |
| 39 | + |
| 40 | +- [collections](https://pythoncomplexity.com/stdlib/collections/): Container datatypes (deque, Counter, OrderedDict, defaultdict, namedtuple, ChainMap) |
| 41 | +- [collections.deque](https://pythoncomplexity.com/stdlib/deque/): O(1) append/pop from both ends |
| 42 | +- [collections.Counter](https://pythoncomplexity.com/stdlib/counter/): Counting and multiset operations |
| 43 | +- [collections.defaultdict](https://pythoncomplexity.com/stdlib/defaultdict/): Dict with default factory |
| 44 | +- [collections.OrderedDict](https://pythoncomplexity.com/stdlib/ordereddict/): Insertion-ordered dict with O(1) move_to_end |
| 45 | +- [collections.namedtuple](https://pythoncomplexity.com/stdlib/namedtuple/): Lightweight named tuples |
| 46 | +- [heapq](https://pythoncomplexity.com/stdlib/heapq/): O(log n) push/pop, O(n) heapify |
| 47 | +- [bisect](https://pythoncomplexity.com/stdlib/bisect/): O(log n) binary search, O(n) insertion |
| 48 | +- [itertools](https://pythoncomplexity.com/stdlib/itertools/): Lazy iterator combinatorics |
| 49 | +- [functools](https://pythoncomplexity.com/stdlib/functools/): Higher-order functions (lru_cache, reduce, partial) |
| 50 | +- [re](https://pythoncomplexity.com/stdlib/re/): Regular expression complexity |
| 51 | +- [json](https://pythoncomplexity.com/stdlib/json/): JSON encoding/decoding complexity |
| 52 | +- [datetime](https://pythoncomplexity.com/stdlib/datetime/): Date/time operations |
| 53 | +- [math](https://pythoncomplexity.com/stdlib/math/): Mathematical functions |
| 54 | +- [hashlib](https://pythoncomplexity.com/stdlib/hashlib/): Cryptographic hash functions |
| 55 | +- [pathlib](https://pythoncomplexity.com/stdlib/pathlib/): Filesystem path operations |
| 56 | +- [sqlite3](https://pythoncomplexity.com/stdlib/sqlite3/): SQLite database operations |
| 57 | +- [difflib](https://pythoncomplexity.com/stdlib/difflib/): Sequence comparison (SequenceMatcher, unified_diff) |
| 58 | +- [copy](https://pythoncomplexity.com/stdlib/copy/): Shallow and deep copy complexity |
| 59 | +- [array](https://pythoncomplexity.com/stdlib/array/): Typed array operations |
| 60 | +- [queue](https://pythoncomplexity.com/stdlib/queue/): Thread-safe queue implementations |
| 61 | +- [decimal](https://pythoncomplexity.com/stdlib/decimal/): Arbitrary-precision decimal arithmetic |
| 62 | +- [graphlib](https://pythoncomplexity.com/stdlib/graphlib/): Topological sorting |
| 63 | +- [operator](https://pythoncomplexity.com/stdlib/operator/): Function versions of operators |
| 64 | +- [random](https://pythoncomplexity.com/stdlib/random/): Random number generation |
| 65 | +- [statistics](https://pythoncomplexity.com/stdlib/statistics/): Statistical functions |
| 66 | +- [string](https://pythoncomplexity.com/stdlib/string/): String constants and templates |
| 67 | +- [struct](https://pythoncomplexity.com/stdlib/struct/): Binary data packing/unpacking |
| 68 | +- [typing](https://pythoncomplexity.com/stdlib/typing/): Type hint support |
| 69 | + |
| 70 | +## Python Implementations |
| 71 | + |
| 72 | +- [CPython](https://pythoncomplexity.com/implementations/cpython/): Reference implementation details |
| 73 | +- [PyPy](https://pythoncomplexity.com/implementations/pypy/): JIT-compiled implementation differences |
| 74 | +- [Jython](https://pythoncomplexity.com/implementations/jython/): JVM-based implementation differences |
| 75 | +- [IronPython](https://pythoncomplexity.com/implementations/ironpython/): .NET-based implementation differences |
| 76 | + |
| 77 | +## Python Versions |
| 78 | + |
| 79 | +- [Python 3.14](https://pythoncomplexity.com/versions/py314/): Complexity changes in 3.14 |
| 80 | +- [Python 3.13](https://pythoncomplexity.com/versions/py313/): Complexity changes in 3.13 |
| 81 | +- [Python 3.12](https://pythoncomplexity.com/versions/py312/): Complexity changes in 3.12 |
| 82 | +- [Python 3.11](https://pythoncomplexity.com/versions/py311/): Complexity changes in 3.11 |
| 83 | +- [Python 3.10](https://pythoncomplexity.com/versions/py310/): Complexity changes in 3.10 |
| 84 | +- [Python 3.9](https://pythoncomplexity.com/versions/py39/): Complexity changes in 3.9 |
0 commit comments