It's a question from 《introduction to algorithms》whose number is 4.4-5 and is described like this:
Use a recursion tree to determine a good asymptotic upper bound on the recurrence T(n) = T(n-1) + T(n/2) + n.Use the substitution method to verify your answer.
I found it is difficult to me to calculate the recursion tree's recurrence. The answer I gave
Math.pow(2,n)
seems too loose.Maybe there is some better guess existed.Thanks for any help.
Worst Case Upper Bound: A function that is a boundary above the algorithms' runtime function, when that algorithm is given the inputs that maximize the algorithm's run time.
Upper bound of an algorithm is shown by the asymptotic notation called Big Oh(O) (or just Oh).
If you divide a polynomial function f(x) by (x - c), where c > 0, using synthetic division and this yields all positive numbers, then c is an upper bound to the real roots of the equation f(x) = 0. Note that two things must occur for c to be an upper bound. One is c > 0 or positive.
In mathematics, particularly in order theory, an upper bound or majorant of a subset S of some preordered set (K, ≤) is an element of K that is greater than or equal to every element of S. Dually, a lower bound or minorant of S is defined to be an element of K that is less than or equal to every element of S.
Hope I did no mistakes :)
let's A(n)=T(n/2)+n
0. T(n)=T(n-1)+A(n)=T(n-2)+A(n-1)+A(n)=...=A(1)+A(2)+...+A(n)
T(n)=sum[1..n]A(n)
T(n)=sum[i=1..n]T(i/2)+sum[i=1..n]i
assuming n/2
is integer division, T(n/2)=T((n+1)/2)
for even n
, so the first sum consists of two equal halves: T(1)+T(1)+T(2)+T(2)+...
1. T(n)=2*sum[1..n/2]T(i)+n*(n-1)/2
since T(n)<=T(m) for every n<=m
2. T(n)<=n*T(n/2)+n*(n-1)/2
since T(n/2)>=n/2>=(n-1)/2
3. T(n)<=n*T(n/2)+n*T(n/2)=2*n*T(n/2)
let's consider this for only n=2^k
, since T
is monotonous: n=2^k
and U(k)=T(2^k)
4. U(k)<=2*(2^k)*U(k-1)=2^(k+1)*U(k-1)
let L(k)=log2 U(k)
5. L(k)<=k+1+L(k-1)
just like we did between step0 and step1
6. L(k)<=k*(k-1)/2+k=k*k/2-k/2+k<=k*k
7. U(k)=2^L(k)<=2^squared(k)
8. T(n)=U(log2 n)<=2^squared(log2 n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With