【发布时间】:2014-04-11 17:07:30
【问题描述】:
A[n];
Sort(p,r)
{
if (A[p] > A[r]) then
A[p]<->A[r]; //exchange
if (p+1 >= r) then
return;
q <- (r-p+1) / 3;
Sort(p, r-q); // 2/3 of head
Sort(p+q, r); // 2/3 of tail
Sort(p, r-q); // again, 2/3 of head
}
大家好。
这是我学习的问题。
该算法适用于排序。
n time
15 0.004
16 0.008
17 0.017
18 0.034
19 0.072
20 0.143
21 0.283
22 0.572
23 1.154
24 2.296
25 4.604
26 9.23
27 18.517
以上是n的时间。
(示例:如果 n 为 15,则像这样工作。Sort(0,14))
时间复杂度似乎是 2^n 指数。对吧?
但我不知道它是怎样的,因为我认为它是 T(n) = 3T((2/3)*n) + 1 = 3^n。 它与我所拥有的实时不匹配... 需要帮助,请。
【问题讨论】:
-
你确定你对重复的限制很严格吗?
标签: algorithm sorting time-complexity exponential