python - 递归深度和一个事实?
问题描述
我看到这段文字:
出现一个问题:
但是你在正常的快速排序中看到,当我们在一个子数组中有 1 个元素,在下一个子数组中有 n-1 个元素时,我们在使用堆栈时得到 O(n) 的深度。这与这个事实相反吗?问题出在哪里?
我对这个话题的误解在哪里?
解决方案
The important part is "constant fraction of the elements". If you hit a degenerate Quicksort case where the partitioning puts a constant number (e.g. 1) of elements on one side of the partition, you'll get O(n^2) time complexity.
But if every partitioning call puts a constant fraction (e.g. 99%) of elements on one side, you'll still get O(n log n) (albeit with a larger constant factor).
推荐阅读
- python - concurrent.futures 'NoneType' 对象不可调用
- android - Xamarin 的 WebView 滚动行为在某些设备上很奇怪
- javascript - 将javascript中的分数计数器显示为html中的文本
- firebase - 是否可以阻止 Web 客户端在有权上传到 Google Cloud Storage 时设置 Cache-Control?
- java - 使用多个 WAR 时在 Java Tomcat 应用程序中查找上下文时出错
- css - 添加到 CSS 类中的“a”是什么
- python - 访问元组元素时出现错误“对象不可下标”。错误取决于使用情况
- r - 防止情节重新调整轴的大小
- python - Python 错误:thon setup.py egg_info 检查日志以获取完整的命令输出
- python - 如何在熊猫中自定义透视表