【发布时间】:2014-02-28 19:13:33
【问题描述】:
有谁知道 Python 在内部对 list.sort() 使用什么类型的排序?或者它至少保证 O(n*log(n))? docs 不多说。看了this question
后我想知道【问题讨论】:
标签: python arrays sorting big-o
有谁知道 Python 在内部对 list.sort() 使用什么类型的排序?或者它至少保证 O(n*log(n))? docs 不多说。看了this question
后我想知道【问题讨论】:
标签: python arrays sorting big-o
Python 使用 TimSort,这是 Tim Peters 开发的一种新算法。
这是一个 O(NlogN) 排序算法,是的,适用于最坏情况和平均情况。在理想情况下,它会提高到 O(N)。请参阅Python Wiki Time Complexity page 和我链接到的维基百科文章。
请注意,该算法已被证明非常流行,并且已被添加到 Java SE 7、Android 和 GNU Octave 中。
【讨论】: