以下排序算法的最坏情况是 O(n^2) 吗?我用了主定理
Is the worst case scenario for the following sorting algorithm O(n^2)? I used the master theorem
我应该为以下排序算法找出最坏情况下的时间复杂度。使用主定理,我得到了 O(n^2)。我想检查一下我的回答是否正确。
SomeSort (A, b, e)
if e = b + 1 then
if A[b] > A[e] then
exchange A[b] and A[e]
end if
else if e > b + 1 then
p ←− [(e-b+1)/3] * the [] represents floor division
SomeSort (A, b, e − p)
SomeSort (A, b + p, e)
SomeSort (A, b, e − p)
end if
运行次重现为
T(n) = 3T(2n/3) = 3T(n/(3/2)),
因此主定理的情况 1 适用,运行 时间是
Theta(n^(log(3)/log(3/2))) = Omega(n^2.7).
我应该为以下排序算法找出最坏情况下的时间复杂度。使用主定理,我得到了 O(n^2)。我想检查一下我的回答是否正确。
SomeSort (A, b, e)
if e = b + 1 then
if A[b] > A[e] then
exchange A[b] and A[e]
end if
else if e > b + 1 then
p ←− [(e-b+1)/3] * the [] represents floor division
SomeSort (A, b, e − p)
SomeSort (A, b + p, e)
SomeSort (A, b, e − p)
end if
运行次重现为
T(n) = 3T(2n/3) = 3T(n/(3/2)),
因此主定理的情况 1 适用,运行 时间是
Theta(n^(log(3)/log(3/2))) = Omega(n^2.7).