我应该为以下排序算法找到最坏情况下的时间复杂度。使用主定理,我得到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
答案 0 :(得分:2)
运行时间重复是
product
因此,主定理的情况1适用,并且运行时间为
T(n) = 3T(2n/3) = 3T(n/(3/2)),