Python中元组的时间复杂度 [英] Time complexity of tuple in Python

查看:125
本文介绍了Python中元组的时间复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于哈希(字典)和列表也有类似的问题,这里也有很多信息: 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.



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.

    这篇关于Python中元组的时间复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆