本文介绍了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反向列表的时间复杂度是多少?
发布评论