Algorithm 以下排序算法的最坏情况是否为O(n^2)?我使用了主定理
我应该为下面的排序算法找到最坏情况下的时间复杂度。利用主定理,我得到了O(n^2)。我想看看我的答案是否正确Algorithm 以下排序算法的最坏情况是否为O(n^2)?我使用了主定理,algorithm,sorting,pseudocode,Algorithm,Sorting,Pseudocode,我应该为下面的排序算法找到最坏情况下的时间复杂度。利用主定理,我得到了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
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).
运行时间循环为
T(n) = 3T(2n/3) = 3T(n/(3/2)),
因此,主定理的情况1适用,运行时间为
Theta(n^(log(3)/log(3/2))) = Omega(n^2.7).