【刷题】时间复杂度
This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than a factor of O(log n).
Generally, 'n' is the number of elements currently in the container. 'k' is either the value of a parameter or the number of elements in the parameter.
list
The Average Case assumes parameters generated uniformly at random.
Internally, a list is represented as an array; the largest costs come from growing beyond the current allocation size (because everything must move), or from inserting or deleting somewhere near the beginning (because everything after that must move). If you need to add/remove at both ends, consider using a collections.deque instead.
| Operation | Average Case |
|---|---|
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
| Copy | O(n) |
