Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 以下排序算法的最坏情况是否为O(n^2)?我使用了主定理_Algorithm_Sorting_Pseudocode - Fatal编程技术网

Algorithm 以下排序算法的最坏情况是否为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

我应该为下面的排序算法找到最坏情况下的时间复杂度。利用主定理,我得到了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).

运行时间循环为

T(n) = 3T(2n/3) = 3T(n/(3/2)),
因此,主定理的情况1适用,运行时间为

Theta(n^(log(3)/log(3/2))) = Omega(n^2.7).