Complexity of list.index(x) in Python

后端 未结 6 1160
礼貌的吻别
礼貌的吻别 2020-12-03 04:27

I\'m referring to this: http://docs.python.org/tutorial/datastructures.html

What would be the running time of list.index(x) function in terms of big O n

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 04:56

    It's O(n), also check out: http://wiki.python.org/moin/TimeComplexity

    This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than a factor of O(log n)...

提交回复
热议问题