最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python中元组的时间复杂度

SEO心得admin40浏览0评论
本文介绍了Python中元组的时间复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

发布评论

评论列表(0)

  1. 暂无评论