简体   繁体   English

解决T(n-1)+ sqrt(n)的递归

[英]Solving recurrence for T(n-1) + sqrt(n)

I'm hoping that I'm going about this problem the correct way. 我希望我能以正确的方式解决这个问题。 It asks to solve the recurrence: 它要求解决重复:

T(n) = T(n-1) + sqrt(n)

So far I have researched and been able to get to this point: 到目前为止,我已经研究并能够达到这一点:

T(n) = T(n-2) + (n-1) + sqrt(n) T(n) = T(n-3) + (n-2) + (n-1) + sqrt(n) T(n) = T(0) + 1 + 2 + ... + (n-2) + (n-1) + sqrt(n)

I'm having trouble understanding what the pattern may be to solve for 1+2+...+sqrt(n) 我在理解1 + 2 + ... + sqrt(n)可能要解决的模式时遇到麻烦

You start with unrolling the recursion and you should receive a sum of square roots. 从展开递归开始,您应该收到平方根的总和。 The sum of square roots is a generalized harmonic number and yours one can be approximated with: 平方根之和是一个广义谐波数 ,您的平方根可以近似表示为:

在此处输入图片说明

The second line is already wrong. 第二行已经错了。

If T (n) = T (n - 1) + sqrt (n), then T (n - 1) = T (n - 2) + sqrt (n - 1), therefore 如果T(n)= T(n-1)+ sqrt(n),则T(n-1)= T(n-2)+ sqrt(n-1),因此

T (n) = T (n - 2) + sqrt (n - 1) + sqrt (n) T(n)= T(n-2)+ sqrt(n-1)+ sqrt(n)

T (n) = T (n - 3) + sqrt (n - 2) + sqrt (n - 1) + sqrt (n) T(n)= T(n-3)+ sqrt(n-2)+ sqrt(n-1)+ sqrt(n)

T (n) = T (n - 4) + sqrt (n - 3) + sqrt (n - 2) + sqrt (n - 1) + sqrt (n) T(n)= T(n-4)+ sqrt(n-3)+ sqrt(n-2)+ sqrt(n-1)+ sqrt(n)

and so on. 等等。

The sum of the square roots from 1 to n is about the same as the integral of sqrt (x) from 1 to n. 从1到n的平方根之和与从1到n的sqrt(x)的积分大致相同。

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

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