简体   繁体   English

计算递归关系 T(n)=T(n / log n) + Θ(1)

[英]Calculating the Recurrence Relation T(n)=T(n / log n) + Θ(1)

The question comes from Introduction to Algorithms 3rd Edition, P63, Problem 3-6, where it's introduced as Iterated functions .问题来自Introduction to Algorithms 3rd Edition, P63, Problem 3-6,在那里它被引入为Iterated functions I rewrite it as follows:我改写如下:

int T(int n){
   for(int count = 0; n > 2 ; ++count)
   {
      n = n/log₂(n); 
   }
   return count;
}

Then give as tight a bound as possible on T(n) .然后在T(n)上给出尽可能严格的界限。

I can make it O(log n) and Ω(log n / log log n) , but can it be tighter?我可以使它成为O(log n)Ω(log n / log log n) ,但它可以更紧吗?


PS: Using Mathematica, I've learned that when n=1*10^3281039 , T(n)=500000 PS:使用 Mathematica,我了解到当n=1*10^3281039T(n)=500000

and the same time, T(n)=1.072435*log n/ log log n同时, T(n)=1.072435*log n/ log log n

and the coefficient declines with n from 1.22943 ( n = 2.07126*10^235 ) to 1.072435 ( n = 1*10^3281039 ).并且系数随着n1.22943 ( n = 2.07126*10^235 ) 1.0724351.072435 ( n = 1*10^3281039 )。

May this information be helpful.愿此信息有所帮助。

It looks like the lower bound is pretty good, so I tried to proof that the upper bound is O(log n / log log n) .看起来下界很不错,所以我试图证明上界是O(log n / log log n) But let me first explain the other bounds (just for a better understanding).但让我首先解释其他界限(只是为了更好地理解)。

TL;DR TL; 博士

T(n) is in Θ(log n / log log n) . T(n)Θ(log n / log log n)

T(n) is in O(log n) T(n) 在O(log n)

This can be seen by modifying n := n/log₂n to n := n/2 .这可以通过将n := n/log₂n修改为n := n/2 n := n/log₂n出。
It needs O(log₂ n) steps until n ≤ 2 holds.它需要O(log₂ n)步直到n ≤ 2成立。

T(n) is in Ω(log n / log log n) T(n) 单位为Ω(log n / log log n)

This can be seen by modifying n := n/log₂(n) to n := n/m , where m is the initial value of log n .这可以通过将n := n/log₂(n)n := n/m来看出,其中mlog n的初始值。
Solving the equation n / (log n) x < 2 for x leads us to求解方程n / (log n) x < 2 for x导致我们

log n - x log log n < log 2
    ⇔                log n - log 2 < x log log n
    ⇔  (log n - log 2) / log log n < x

    ⇒ x ∈ Ω(log n / log log n)

Improving the upper bound: O(log n) → O(log n / log log n)提高上限: O(log n) → O(log n / log log n)

Now let us try to improve the upper bound.现在让我们尝试改进上限。 Instead of dividing n by a fixed constant (namely 2 in the above proof) we divide n as long by the initial value of log(n)/2 as the current value of log(n) is bigger.代替除以n由固定常数(即2在上述证明)我们把n只要通过改变初始值log(n)/2为的当前值log(n)更大。 To be more clearer have a look at the modified code:为了更清楚地看一下修改后的代码:

int T₂(int n){
     n_old = n;
     for(int count=0; n>2 ;++count)
     {
         n = n / (log₂(n_old)/2);

         if(log₂(n)) <= log₂(n_old)/2)
         {
            n_old = n;
         }
     }
     return count;
}

The complexity of the function T₂ is clearly an upper bound for the function T , since log₂(n_old)/2 < log₂(n) holds for the whole time.的功能的复杂性T₂显然是一个上限为函数T ,由于log₂(n_old)/2 < log₂(n)保持用于整个时间。

Now we need to know how many times we divide by each 1/2⋅log(n_old) :现在我们需要知道我们除以每个1/2⋅log(n_old)

n / (log(sqrt(n)))x ≤ sqrt(n)
⇔           n / sqrt(n) ≤ log(sqrt(n))x
⇔          log(sqrt(n)) ≤ x log(log(sqrt(n)))

⇔    log(sqrt(n)) / log(log(sqrt(n)))  ≤ x

So we get the recurrence formula T₂(n) = T(sqrt(n)) + O(log(sqrt(n)) / log(log(sqrt(n)))) .所以我们得到递归公式T₂(n) = T(sqrt(n)) + O(log(sqrt(n)) / log(log(sqrt(n))))

Now we need to know how often this formula has to be expanded until n < 2 holds.现在我们需要知道这个公式必须多久扩展一次,直到n < 2成立。

n2-x < 2
⇔       2-x⋅log n < log 2
⇔       -x log 2 + log log n < log 2
⇔       log log n < log 2 + x log 2
⇔       log log n < (x + 1) log 2

So we need to expand the formula about log log n times.所以我们需要将关于log log n次的公式展开。

Now it gets a little bit harder.现在它变得有点困难。 (Have also a look at the Mike_Dog's answer ) (也看看Mike_Dog 的回答

T₂(n) = T(sqrt(n)) + log(sqrt(n)) / log(log(sqrt(n)))
      = Σk=1,...,log log n - 1 2-k⋅log(n) / log(2-k⋅log n))
      = log(n) ⋅ Σk=1,...,log log n - 1 2-k / (-k + log log n))
(1)   = log(n) ⋅ Σk=1,...,log log n - 1 2k - log log n / k
      = log(n) ⋅ Σk=1,...,log log n - 1 2k ⋅ 2- log log n / k
      = log(n) ⋅ Σk=1,...,log log n - 1 2k / (k ⋅ log n)
      = Σk=1,...,log log n - 1 2k / k

In the line marked with (1) I reordered the sum.在标有 (1) 的行中,我对总和进行了重新排序。

So, at the end we "only" have to calculate Σ k=1,...,t 2 k / k for t = log log n - 1 .因此,最后我们“仅”必须为t = log log n - 1计算Σ k=1,...,t 2 k / k At this point Maple solves this to此时 Maple 解决了这个问题

Σk=1,...,t 2k / k = -I⋅π - 2t⋅LerchPhi(2, 1, t)  +2t/t

where I is the imaginary unit and LerchPhi is the Lerch transcendent .其中I是虚数单位, LerchPhiLerch 超越数 Since the result for the sum above is a real number for all relevant cases, we can just ignore all imaginary parts.由于上述总和的结果对于所有相关情况都是实数,我们可以忽略所有虚部。 The Lerch transcendent LerchPhi(2,1,t) seems to be in O(-1/t) , but I'm not 100% sure about it. Lerch 超越LerchPhi(2,1,t)似乎在O(-1/t) ,但我不是 100% 确定。 Maybe someone will prove this.也许有人会证明这一点。

Finally this results in最后这导致

T₂(n) = -2t⋅O(-1/t) + 2t/t = O(2t/t) = O(log n / log log n)

All together we have T(n) ∈ Ω(log n / log log n) and T(n) ∈ O(log n/ log log n) ,我们总共有T(n) ∈ Ω(log n / log log n)T(n) ∈ O(log n/ log log n)
so T(n) ∈ Θ(log n/ log log n) holds.所以T(n) ∈ Θ(log n/ log log n)成立。 This result is also supported by your example data.您的示例数据也支持此结果。

I hope this is understandable and it helps a little.我希望这是可以理解的,它会有所帮助。

The guts of the problem of verifying the conjectured estimate is to get a good estimate of plugging the value验证推测估计的问题的本质是获得一个很好的塞值估计

n / log(n)

into the function进入函数

n --> log(n) / log(log(n))

Theorem :定理

log( n/log(n) ) / log(log( n/log(n) )) = log(n)/log(log(n)) - 1 + o(1)

(in case of font readibility issues, that's little-oh, not big-oh) (在字体可读性问题的情况下,那是小哦,不是大哦)

Proof:证明:

To save on notation, write为了节省符号,写

A = n
B = log(n)
C = log(log(n))

The work is based on the first-order approximation to the (natural) logarithm: when 0 < y < x ,该工作基于(自然)对数的一阶近似:当0 < y < x

log(x) - y/x < log(x - y) < log(x)

The value we're trying to estimate is我们试图估计的价值是

log(A/B) / log(log(A/B)) = (B - C) / log(B - C)

Applying the bounds for the logarithm of a difference gives应用差异对数的界限给出

(B-C) / log(B) < (B-C) / log(B-C) < (B-C) / (log(B) - C/B)

that is,那是,

(B-C) / C < (B-C) / log(B-C) < (B-C)B / (C (B-1))

Both the recursion we're trying to satisfy and the lower bound suggest we should estimate this with B/C - 1 .我们试图满足的递归和下限都表明我们应该用B/C - 1来估计这一点。 Pulling that off of both sides gives把它从两边拉下来给

B/C - 1 < (B-C) / log(B-C) < B/C - 1 + (B-C)/(C(B-1))

and thus we conclude因此我们得出结论

(B-C) / log(B-C) = B/C - 1 + o(1)

If you take away one idea from this analysis to use on your own, let it be the point of using differential approximations (or even higher order Taylor series) to replace complicated functions with simpler ones.如果你从这个分析中拿走一个想法供你自己使用,那就让它成为使用微分近似(甚至更高阶泰勒级数)来用更简单的函数替换复杂函数的重点。 eg once you have the idea to use例如,一旦你有了使用的想法

log(x-y) = log(x) + Θ(y/x) when y = o(x)

then all of the algebraic calculations you need for your problem simply follow directly.那么您的问题所需的所有代数计算都可以直接遵循。

Thanks for the answer of @AbcAeffchen感谢@AbcAeffchen 的回答

I'm the owner of the question, using the knowledge of "the master method" I learned yesterday, the "a little bit harder" part of proof can be done as follows simply.我是题主,利用昨天学到的“大师法”的知识,证明的“有点难”的部分可以简单地做如下。主方法

I will start here:我将从这里开始:

T(n) = T(sqrt(n)) + O(log(sqrt(n)) / log(log(sqrt(n))))
⇔ T(n)=T(sqrt(n)) + O(log n  / log log n)

Let

n=2 k , S(k)=T(2 k ) n=2 k , S(k)=T(2 k )

then we have那么我们有

T(2 k ) =T(2 k/2 ) + O(log 2 k / log log 2 k ) ⇔ S(k) =S(k/2) + O( k/log k) T(2 k ) =T(2 k/2 ) + O(log 2 k / log log 2 k ) ⇔ S(k) =S(k/2) + O( k/log k)

with the master method使用主方法

S(k)=a*S(k/b)+f(k), where a=1, b=2 , f(k)=k/log k = Ω(k log 2 1 +ε ) = Ω(k ε ), S(k)=a*S(k/b)+f(k), 其中a=1, b=2 , f(k)=k/log k = Ω(k log 2 1 +ε ) = Ω( k ε ),

as long as ε∈(0,1)只要ε∈(0,1)

so we can apply case 3. Then所以我们可以应用案例3。然后

S(k) = O(k/log k) S(k) = O(k/log k)

T(n) = S(k) = O(k/log k) = O(log n/ log log n) T(n) = S(k) = O(k/log k) = O(log n/ log log n)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM