1-07Python列表与字典操作的时间复杂度
list内置操作的时间复杂度
Operation | Big-O Efficiency |
indexx[] | O(1) |
index assignment | O(1) |
append | O(1) |
pop() | O(1) |
pop(i) | O(n) |
insert(i,item) | O(n) |
del operator | O(n) |
iteration | O(n) |
contains(in) | O(n) |
get slice(x:y) | O(k) |
del slice |
O(n) |
set slice | O(n+k) |
reverse | O(n) |
concatenate | O(k) |
sort | O(nlog n) |
multiply | O(nk) |
dict内置操作的时间复杂度
Operation | Big-O Efficiency |
copy | O(n) |
get item | O(1) |
set item | O(1) |
delete item | O(1) |
contains(in) | O(1) |
iteration | O(n) |