Hi I solved a question with recursion tree method. Then I reached the below equatition.
n
∑ 3^(i-1)(n - (i - 1))
i=1
I need to find asymptotic upper bound for that equation. Any help would be appreciated.
Wolfram Alpha is a great tool for this: https://www.wolframalpha.com/input/?i=sum(3%5E(i-1)(n+-+i+%2B+1)+for+i+%3D+1..n)
That tool simplifies the sum to: (-2n + 3^(n+1) - 3)/4.
In terms of big-O, that's O(3^n).
Let u(n) = 3^(n-1) + 2*3^(n-2) + ... + n, then
u(n+1) = (3^n + 3^(n-1) + ... + 1) + 3^(n-1) + 2*3^(n-2) + ... + n = (3^(n+1)-1)/2 + u(n) = 3*u(n) + n + 1
u(n) = (3^(n+1) - 2n - 3) / 4.
Related
How can I solve T(n) = T(n-3)+n^2 using iteration?By master theorem answer is O(n^3) but I am having trouble solving it by iteration.
By direct resolution of the recurrence:
This is a linear recurrence of the first order. We first solve the homogeneous part,
T(n) = T(n - 3)
which is solved by a constant (more precisely three constants as three intertwined sequences form the solution).
Now for the non-homogeneous part, we use the Ansatz T(n) = an³ + bn² + cn + d, because we know that the difference of two cubic polynomials is a quadratic one.
Then
a(n³ - (n-3)³) + b(n² - (n-3)²) + c(n - (n-3)) = 9an² + 3(-9a + 2b)n + 3(9a - 3b + c) = n²
gives
a = 1/9, b = 1/2, c = 1/2.
Finally
T(n) = (2n³ + 9n² + 9n)/18 + T(0)
and similarly for the two other sequences.
Just try to expand the equation:
T(n) = n^2 + (n-3)^2 + (n-6)^2 + ... + 1 = \Theta(n^3)
T(3) = T(0) + 3²
T(6) = T(3) + 6² = T(0) + 3² + 6²
T(9) = T(6) + 9² = T(0) + 3² + 6² + 9²
...
More generally, T(3N) is the sum of T(0) and nine times the sum of the squared naturals up to N. The well-known Faulhaber formula justifies O(N³).
Similar results hold for T(3N+1) and T(3N+2).
I thought it would be something like this...
T(n) = 2T(n-1) + O(n)
= 2(2T(n-2)+(n-1)) + (n)
= 2(2(2T(n-3)+(n-2))+(n-1))+(n)
= 8T(n-3) + 4(n-2) + 2(n-1) + n
Which ends up being something like the summation of 2i * (n-i), and my book says this ends up being O(2n). Could anybody explain this to me? I don't understand why it's 2n and not just O(n) as the (n-i) will continue n times.
This recurrence has already been solved on Math Stack Exchange. As I solve this recurrence, I get:
T(n) = n + 2(T(n-1))
= n + 2(n - 1 + 2T(n-2)) = 3n - 2 + 2^2(T(n-2))
= 3n - 2 + 4(n - 2 + 2(T(n-3))) = 7n - 10 + 2^3(T(n-3))
= 7n - 10 + 8(n - 3 + 2(T(n-4))) = 15n - 34 + 2^4(T(n-4))
= (2^4 - 1)n - 34 + 2^4(T(n-4))
...and so on.
Effectively the recurrence boils down to:
T(n) = (2n+1) * T(1) − n − 2
See the Math Stack Exchange link for how we arrive at this solution. Taking T(1) to be constant, the dominating factor in the above recurrence is (2(n + 1)).
Therefore, the rate of growth of given recurrence is O(2n).
I have the following harmonic sequence:
h(n) = 1 + 1/2 + 1/3 + 1/4 +...+ 1/n
Id like to prove that there's a recurrence with
h(n) (less than or equal to) h( lowerbound( n/2)) + 1
This belongs on math.SE, but we have
h(2n) - h(n) = 1/(n/2 + 1) + 1/(n/2 + 2) + ... + 1/n
< 1/(n/2) + 1/(n/2) + ... + 1/(n/2)
= 1,
since there are n/2 terms. I'll leave the odd case as an exercise.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I am having some issues on how to solve recurrence relations.
T(n) = T(n/2) + log2(n), T(1) = 1, where n is a power of 2
This is a homework problem, so don't just give me the answer. I was just wondering how to start the problem.
In class we went over the Master theorem. But I don't think that would be the best way to solve this particular relation.
I don't really know how to start the problem... should I just be going
T(n) = T(n/2) + log_base2(n)
T(n/2) = [T(n/4)+log_base2(n/2)]
T(n) = [T(n/4)+log_base2(n/2)] + log_base2(n)
And just keep working my way down to get something I can see makes a basic equation?
This recurrence solves to Θ((log n)2). Here are two ways to see this.
Some Substitutions
If you know that n is a perfect power of two (that is, n = 2k), you can rewrite the recurrence as
T(2k) = T(2k-1) + k
Let's define a new recurrence S(k) = T(2k). Then we get that
S(k) = S(k - 1) + k
If we expand out this recurrence, we get that
S(k) = S(k - 1) + k
= S(k - 2) + (k - 1) + k
= S(k - 3) + (k - 2) + (k - 1) + k
= S(k - 4) + (k - 3) + (k - 2) + (k - 1) + k
...
= S(0) + 1 + 2 + 3 + ... + k
= S(0) + Θ(k2)
Assuming S(0) = 1, then this recurrence solves to Θ(k2).
Since S(k) = T(2k) = T(n), we get that T(n) = Θ(k2) = Θ(log2 n).
Iterating the Recurrence
Another option here is to expand out a few terms of the recurrence and to see if any nice patterns emerge. Here’s what we get:
T(n) = T(n / 2) + lg n
= T(n / 4) + lg (n / 2) + lg n
= T(n / 8) + lg (n / 4) + lg (n / 2) + lg n
...
Eventually, after lg n layers, this recurrence bottoms out and we’re left with this expression:
lg n + lg (n / 2) + lg (n / 4) + ... + lg (n / 2lg n)
Using properties of logarithms, we can rewrite this as
lg n + (lg n - 1) + (lg n - 2) + (lg n - 3) + ... + (lg n - lg n)
Or, written in reverse, this is the sum
0 + 1 + 2 + 3 + ... + lg n
That sum is Gauss’s sum up to lg n, which evaluates to (lg n)(lg n + 1) / 2 = Θ((log n)2).
Hope this helps!
If n is a power of 2 then you can just expand out the recurrence and solve exactly, using that lg(a/b) = lg(a) - lg(b).
T(n) = lg(n) + lg(n/2) + lg(n/4) + ... + lg(1) + 1
= (lg(n) - 0) + (lg(n) - 1) .... + (lg(n) - lg(n)) + 1
= lg(n)*lg(n) - lg(n)*(lg(n)+1)/2 + 1
= lg(n)*lg(n)/2 - lg(n)/2 + 1
This can be done with the Akra-Bazzi theorem. See the third example in http://people.mpi-inf.mpg.de/~mehlhorn/DatAlg2008/NewMasterTheorem.pdf.
This can be solved with Master theorem. Your a=1 and b=2 and f(n) = log(n). Then c = log2(1) = 0. Because of your c and f(n) you fall into the second case (where k=1).
So the solution is Θ(log2 n)
I can find the sum of each row (n/log n-i) and also I can draw its recursive tree but I can't calculate sum of its rows.
T(n)=2T(n/2)+n/logn
T(1) = 1
Suppose n = 2^k;
We know for harmonic series (euler formula):
Sum[i = 1 to n](1/i) ~= log(n) [n -> infinity]
t(n) = 2t(n/2) + n/log(n)
= 2(2t(n/4) + n/2/log(n/2)) + n/log(n)
= 4t(n/4) + n/log(n/2) + n/log(n)
= 4(2t(n/8) + n/4/log(n/4)) + n/log(n/2) + n/log(n)
= 8t(n/8) + n/log(n/4) + n/log(n/2) + n/log(n)
= 16t(n/16) + n/log(n/8) + n/log(n/4) + n/log(n/2) + n/log(n)
= n * t(1) + n/log(2) + n/log(4) + ... + n/log(n/2) + n/log(n)
= n(1 + Sum[i = 1 to log(n)](1/log(2^i)))
= n(1 + Sum[i = 1 to log(n)](1/i))
~= n(1 + log(log(n)))
= n + n*log(log(n)))
~= n*log(log(n)) [n -> infinity]
When you start unrolling the recursion, you will get:
Your base case is T(1) = 1, so this means that n = 2^k. Substituting you will get:
The second sum behaves the same as harmonic series and therefore can be approximated as log(k). Now that k = log(n) the resulting answer is:
Follow Extended Masters Theorem Below.
Using Extended Masters Theorem T(n)=2T(n/2)+n/logn can be solved easily as follows.
Here n/log n part can be rewritten as n * (logn)^-1,
Effictively maaking value of p=-1.
Now Extended Masters Theorem can be applied easily, it will relate to case 2b of Extended Masters Theorem .
T(n)= O(nloglogn)
Follow this for more detailed explanation
https://www.youtube.com/watch?v=Aude2ZqQjUI