Solving Recurrence Equations for Algorithm Analysis

In summary, the person is trying to solve a recurrence equation in order to perform algorithm analysis. They got the recurrence from the algorithm they developed and their maths was rusty from years ago. They attempted to solve the equation, but were not able to simplify it further. They need to apply substitution, recursion tree, or master theorem method to finish the equation.
  • #1
kaalen
20
0

Homework Statement


I need to solve a recurrence equation in order to perform algorithm analysis. I got the recurrence from the algorithm I developed. It's been years since I did my undergrad degree and my maths is rusty.

Homework Equations


[itex]T(n)= 1+ \sum_{i=1}^n2(n-i+T(i)) [/itex]


The Attempt at a Solution


This is how far I got:
[itex]T(n)= 1+ \sum_{i=1}^n(2n-2i+2T(i)) [/itex]
[itex]T(n)= 1+ 2\sum_{i=1}^nn-2\sum_{i=1}^ni+2\sum_{i=1}^nT(i) [/itex]
[itex]T(n)= 1+ 2n^2-2\frac{n(n+1)}{2}+2\sum_{i=1}^nT(i) [/itex]
[itex]T(n)= 1+ n^2-n+2\sum_{i=1}^nT(i) [/itex]

I'm not sure what to do with that T(i) in the sum. I tried this:
[itex]T(n)= 1+ n^2-n+2\frac{T(n)(T(n)+1)}{2} [/itex]
[itex]T(n)= 1+ n^2-n+T(n)T(n)+T(n) [/itex]

But what do I do with that T(n)T(n)? Can it be further simplified?
Can I say [itex]T(n)T(n)=T^2(n)[/itex] or [itex]T(n)T(n)=T(n^2)[/itex]

When I'm done simplifying I need to apply substitution, recursion tree or master theorem method to finish it off.
 
Physics news on Phys.org
  • #2
Forget your approach [itex]T(n)= 1+ n^2-n+2\frac{T(n)(T(n)+1)}{2}[/itex] That doesn't work!
Instead, rewrite T(n) as
[tex] T(n) = -1 -n^2 + n - 2 \sum_{i=1}^{n-1} T(i)[/tex]
Then start with T(1):
[tex] T(1) = -1 - 1^2 + 1 = -1 [/tex]
Now
[tex] T(2) = -1 - 2^2 + 2 - 2 * ( -1 -1^2 + 1) [/tex]
Now
[tex] T(3) = -1 - 3^2 + 3 - 2 * ( -1 - 2^2 + 2 - 2 * (-1 - 1^2 + 1)) [/tex]
[tex] T(3) = - 1 - 3^2 + 3 + (-2) * (-1 - 2^2 + 2) + (-2)^2 * (-1 - 1^2 + 1) [/tex]
[tex] T(3) = -1 + (-2) * (-1) + (-2)^2 * (-1) - 3^2 + (-2) * (-2^2) + (-2)^2 * (-1^2) + 3 + (-2) * 2 + (-2)^2 * 1 [/tex]
Do you see the pattern? For T(n), you get
[tex] T(n) = - \sum_{i=0}^{n-1} (-2)^i - \sum_{i=0}^{n-1} (n-i)^2 (-2)^i + \sum_{i=0}^{n-1} (n-i) (-2)^i [/tex]
Now, all you need to do is look up the partial sums, e.g. here http://en.wikipedia.org/wiki/List_of_mathematical_series#Power_series and use you favorpite CAS software to simplify the expressions. Good luck!
 
  • #3
susskind_leon said:
Forget your approach [itex]T(n)= 1+ n^2-n+2\frac{T(n)(T(n)+1)}{2}[/itex] That doesn't work!
Instead, rewrite T(n) as
[tex] T(n) = -1 -n^2 + n - 2 \sum_{i=1}^{n-1} T(i)[/tex]

Hmm... haven't even thought about it this way. Mighty thanks for opening my eyes. I have since realized I had to fix my recurrence a bit because the algorithm calls itself on input from 1 to n-1, rather than to n (it would be calling itself till infinity that way).
So the corrected equation is
[tex] T(n) = 1 -n+ n^2 + 2 \sum_{i=1}^{n-1} T(i)[/tex]
Few minutes ago I fed the numbers in and am now trying to figure out what the pattern is.
I noticed one thing in your proposed solution though and am hoping you can shed some more light before I proceed

How did you get from [tex]T(n)= 1+ n^2-n+2\sum_{i=1}^{n}T(n)[/tex] to
[tex] T(n) = -1 -n^2 + n - 2 \sum_{i=1}^{n-1} T(i)[/tex]. Prefixes seem to have magically changed from + to - and vice versa and you seemed to have corrected [tex]\sum_{i=1}^{n}[/tex] to [tex]\sum_{i=1}^{n-1}[/tex] before I even noticed it's wrong. Just a lapsus?
 
  • #4
Firstly, it's [itex]1+ n^2-n+2\sum_{i=1}^{n}T(i)[/itex] and not [itex]1+ n^2-n+2\sum_{i=1}^{n}T(n)[/itex].
[tex]T(n)= 1+ n^2-n+2\sum_{i=1}^{n}T(i)= 1+ n^2-n+2\sum_{i=1}^{n-1}T(i)+2T(n)[/tex]
Then you substract the last term and you get
[tex] T(n) - 2 T(n) = -T(n) = 1+ n^2-n+2\sum_{i=1}^{n}T(i) [/tex]
Then, you multiply by -1 and you finally get
[tex] T(n) = -1 -n^2 + n - 2\sum_{i=1}^{n}T(i) [/tex]
Regards!
 

FAQ: Solving Recurrence Equations for Algorithm Analysis

1. What is a recurrence equation with sum?

A recurrence equation with sum is a mathematical equation that describes a sequence of values by relating each term to one or more previous terms. These equations often involve a summation of terms, which is where the "sum" part of the name comes from.

2. How is a recurrence equation with sum different from a regular recurrence equation?

A regular recurrence equation relates each term to only the previous term, whereas a recurrence equation with sum can involve multiple previous terms. Additionally, a regular recurrence equation may not involve a summation, whereas a recurrence equation with sum always does.

3. What is the purpose of using a recurrence equation with sum?

Recurrence equations with sum are useful for modeling processes that involve the accumulation of values over time. They can also be used to find closed-form solutions for iterative algorithms or to analyze the time complexity of algorithms.

4. How do you solve a recurrence equation with sum?

Solving a recurrence equation with sum involves using various techniques such as substitution, telescoping, or generating functions. In some cases, it may also be possible to use known summation formulas to simplify the equation.

5. Can recurrence equations with sum be applied to real-world problems?

Yes, recurrence equations with sum can be used to model and solve real-world problems in a variety of fields such as economics, physics, and computer science. They are particularly useful for analyzing processes that involve repeated iterations or accumulation of values.

Similar threads

Replies
3
Views
937
Replies
1
Views
770
Replies
2
Views
653
Replies
1
Views
945
Replies
1
Views
803
Replies
8
Views
1K
Replies
3
Views
1K
Replies
6
Views
853
Replies
4
Views
1K
Back
Top