python shuffle算法性能

标签 python performance time-complexity shuffle

我想知道 shuffle function 的时间复杂度在 random Python 库/模块中。是 O(n) 还是小于它?

是否有网站显示属于 Python 库的函数的时间复杂度?

最佳答案

你不能在小于 O(n) 的时间内以完全随机的方式打乱列表。

implementation of random.shuffle()使用 Fisher-Yates shuffle algorithm ,很容易看出是 O(n)。

关于python shuffle算法性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9371079/

相关文章:

java - 在 Servlet session 中缓存 Hibernate 实体

string - 有效地计算可被k整除的数字字符串的子字符串的数量?

python - 在无向图中查找最大节点数

java - 大 o 符号和递归函数

python - 张量对于图形分布来说太大 - "InternalError: Message length was negative"

python - Tkinter Canvas 不显示

python - xlwings for Excel for Mac 2016

performance - 计算内存访问的平均时间

c++ - 内联函数参数传递

python - 如何在不绑定(bind) IP 的情况下在特定端口上运行服务