I have been asked to solve that recurrence relation. I got the next solution: 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
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.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.