关于哈希(字典)和列表也有类似的问题,这里也有很多信息: wiki.python/moin/TimeComplexity
There is similar question about hash (dictionaries) and lists, also there is a good piece of info here: wiki.python/moin/TimeComplexity
但是我没有找到有关元组的任何信息。
But I didn't find anything about tuples.
The access time for
data_structure[i]
- 对于链表通常是O(n)
- 对于字典是〜O(1)
元组怎么样? 是链表的O(n)还是数组的O(1)?
What about tuple? Is it O(n) like for a linked list or O(1) like for an array?
推荐答案列表和元组均为O(1)。它们在道德上都等效于整数索引数组。
It's O(1) for both list and tuple. They are both morally equivalent to an integer indexed array.