Python反向列表的时间复杂度是多少?

编程入门 行业动态 更新时间:2024-10-11 03:22:51
本文介绍了Python反向列表的时间复杂度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我看过此页面 wiki.python/moin/TimeComplexity,但我看不到列表中的reverse()函数. list的reverse()的时间时间复杂度是多少?

I have seen this page wiki.python/moin/TimeComplexity but I don't see the reverse() function in there for lists. What is the time time complexity of list's reverse()?

我对时间的实验表明,对于较大的尺寸,它为O(n).有人可以确认吗?

My experiments with time indicate that it is O(n) for larger sizes. Can anyone confirm it ?

timeit反转大小列表的时间

timeit Time to reverse a list of size

10 .1027 100 .2347 1000 .6704 10000 6.204 20000 12.9

推荐答案

是的,您是对的,它是O(n),其中n-列表的长度. 在此处查找更多信息: www.ics. uci.edu/~pattis/ICS-33/lectures/complexitypython.txt

Yes, you are right, it is O(n) where n - length of list. Look here for more information: www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt

更多推荐

Python反向列表的时间复杂度是多少?

本文发布于:2023-11-29 13:49:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂度   时间   列表   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!