algorithm - 查找递归算法的运行时间
问题描述
我正在尝试查找此算法的运行时(用于查找数组中的第 k 个最小值):
Select(A[1 . . . n], k) if n ≤ 100 then
Return the k-th smallest element via brute-force; else
Divide A into m ← ⌈n/3⌉ consecutive subgroups of size at most 3;
for i ← 1 . . . m do
M[i] ← Median of the i-th subgroup;
end
p ← Select(M[1...m],⌊m/2⌋);
Let B be an array contains all the elements < p in A;
Let C be an array contains all the elements ≥ p in A;
if len(B) ≥ k then
return Select(B,k);
else
return Select(C, k − len(B));
end
end
我试图提出一个递归关系以找到运行时。这就是我认为的:
由于该算法对数组的 n/3 个元素进行递归调用,因此我希望它是 2T(n/3) + O(n)。然后应用大师定理。我是否朝着正确的方向前进?
解决方案
推荐阅读
- c# - 单例模式在提交 .this 时完成的具体任务是什么?
- excel - 如何使用 Powershell 修改 Excel VBA 标签
- python - 从 .CSV 导入数据,在列内搜索
- ios - Nightwatch.js - 无法使用 Appium(iOS 模拟器)执行 touchAction 或滚动,正在寻找解决方案
- azure - Azure 搜索 - 按搜索词和页面顺序
- swift - 更新到 10.15 后 xcode 仍然显示版本错误
- javascript - 为什么我在将 javascript 连接到简单 html 时出错?
- javascript - 在 Js 函数中创建第二个提示
- java - JAVA 不可变,复制链表
- curl - 从 curl 中的下载链接下载文件