简体   繁体   English

求解递归关系:T(n)= T(n-1)+ n-1

[英]Solving a Recurrence Relation: T(n) = T(n-1) + n-1

I have been asked to solve that recurrence relation. 我被要求解决这种复发关系。 I got the next solution: https://imgur.com/a/xWoTI40 我得到了下一个解决方案: https//imgur.com/a/xWoTI40

So I decided to ask my teacher if it was right. 所以我决定问我的老师这是不对的。 He told me that it wasn't; 他告诉我,事实并非如此; and that this is the right solution: https://imgur.com/a/CGD0ta8 这是正确的解决方案: https//imgur.com/a/CGD0ta8

I'm totally clueless right now. 我现在完全无能为力。 The most I try to understand why mine is wrong; 我最努力理解为什么我的错了; the most I think it's actually right. 我认为它是最正确的。

Can somebody explain? 有人可以解释一下吗?

Your solution is correct. 你的解决方案是对的。 Here's a different approach with the same result: 这是一个不同的方法,结果相同:

t(1) = 0 (given)
t(2) = t(1) + 1 = 1
t(3) = t(2) + 2 = 1 + 2 = 3
t(4) = t(3) + 3 = 1 + 2 + 3 = 6
...
t(n) = 1 + 2 + ... + (n-1) = n * (n - 1) / 2 = Theta(n^2).

The teacher's solution is wrong after the second = sign. 在第二个=符号后,教师的解决方案是错误的。 Here's what the teacher wrote: 这是老师写的:

t(n-1) + n - 1 = t(n-2) + n - 1 - 2

But actually the following is correct: 但实际上以下是正确的:

t(n-1) + n - 1 = ( t(n-2) + n - 2 ) + n - 1

which is actually exactly what you got. 这实际上就是你得到的。 It appears that the teacher dropped an n term. 看来,老师下降的n项。

In fact, the teacher's solution ends with a dominant term of -n^2 which is clearly wrong, as t(n) >= 0 for all n >= 0 . 实际上,教师的解决方案以-n^2的显性项结束,这显然是错误的,因为对于所有n >= 0t(n) >= 0 n >= 0

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

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