本文介绍了访问元组中元素的时间复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于哈希(字典)和列表也有类似的问题,这里也有很多信息:http://wiki.python.org/moin/TimeComplexity
There is similar question about hash (dictionaries) and lists, also there is a good piece of info here: http://wiki.python.org/moin/TimeComplexity
但是我没有找到有关元组的任何信息.
But I didn't find anything about tuples.
访问时间
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.
这篇关于访问元组中元素的时间复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!