Jun 29, 2012 at 10:19am UTC
Hello
sorry.Can you help me determine the order of the alggorithm
T(n) = T(n-1) + (n-1)/n(n + 1)
?
Thanks in advance!
Jun 29, 2012 at 3:41pm UTC
Not very understand what is the problem.
In fact it can be written in C++ by a recursive function:
Given that T(0) = 0 ( other initial value also ok)
#include <iostream>
using namespace std;
double T(unsigned int n)
{
if(n==0)
return 0;
return T(n-1) + double(n-1)/double(n*(n+1));
}
int main()
{
double to=T(5);
cout<<to<<endl;
}
Output is: 0.616667
Jun 29, 2012 at 4:30pm UTC
Order? Complexity? I think I've heard order get used like that before. In which case, it's linear complexity.
Jun 29, 2012 at 7:11pm UTC
I think that the question is the growth of T(n)
In which case it's logarithmic because it approximates to the harmonic series.
Jun 30, 2012 at 3:12pm UTC
I think that the question is the growth of T(n)
In which case it's logarithmic because it approximates to the harmonic series.
are you surre?Order of magnitude is different from the valu computed.It can compute any value.
Otherwise, why would it call itself n times?
Size of the problem is reduced by just 1 each time.
I just changed T(5) to T(1000) and it makes no difference.
Last edited on Jun 30, 2012 at 3:16pm UTC