What is the time complexity of Python List Reverse?

I saw this page https://wiki.python.org/moin/TimeComplexity , but I do not see the inverse function there for lists. What is the time complexity of the list in the opposite direction?

My experiments over time show that this is O (n) for large sizes. Can anyone confirm this?

timeit Time to resize list

   10    .1027
  100    .2347
 1000    .6704
10000   6.204
20000  12.9
+4
source share
1 answer

Yes, you're right, this is O (n), where n is the length of the list. See here for more information: https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt

+4
source

All Articles