python shuffle算法性能 [英] python shuffle algorithm performance
本文介绍了python shuffle算法性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道 shuffle
random
Python 库/模块中的函数.是 O(n) 还是小于?
I was wondering about the time complexity of the shuffle
function in the random
Python library/module. Is it O(n) or is it less than that?
是否有网站显示属于 Python 库的函数的时间复杂度?
Is there a website that shows the time complexities of functions that belong to Python libraries?
推荐答案
你不能在小于 O(n) 的时间内以完全随机的方式打乱列表.
You cannot shuffle a list in a completely random fashion in less than O(n).
random.shuffle()
的实现 使用 Fisher-Yates shuffle 算法,很容易看出 O(n).
The implementation of random.shuffle()
uses the Fisher-Yates shuffle algorithm, which is easily seen to be O(n).
这篇关于python shuffle算法性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文