retagged by
9,196 views

2 Answers

0 votes
0 votes

 

$$ T(n) = T(n-1) + \frac{1}{n}   ---------(1)$$

$$T(n-1)=T(n-2) + \frac{1}{n-1}-------(2)$$

$$T(n-2)=T(n-3) + \frac{1}{n-2}-------(3)$$

$$\text{put  T(n-1)  from  equation 2 to  eq. 1 then result will be }$$

$$T(n) =T(n-2) + \frac{1}{n} + \frac{1}{n-1}-------(4)$$

$$\text{put  T(n-2)  from  equation 3 to  eq. 4 then result will be }$$

$$T(n) =T(n-3)+ \frac{1}{n} + \frac{1}{n-1} + \frac{1}{n-2}$$

$\text{Similarly we can write-->}$

$$T(n) =T(n-4) + \frac{1}{n-3}+\frac{1}{n-2}+\frac{1}{n-1}+\frac{1}{n} $$

$$ \implies T(n)=T(0)+\sum_{i=1}^{n}\frac{1}{i}=0+H_n, $$

where $H_n$ are the harmonic numbers.

$$H_n=1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\cdot\cdot\cdot+\frac{1}{n}=log(n)$$

$$T(n)=\theta(log(n))$$

Related questions

2 votes
2 votes
1 answer
4
Vaniyesho asked Dec 1, 2016
1,326 views
What is the time complexity of T(n)=T(n-1)+√(n-1)