in Algorithms retagged by
1,416 views
1 vote
1 vote

Time complexity of an algorithm $T(n)$, where $n$ is the input size is given by

$\begin{array}{ll}T(n) & =T(n-1)+\frac{1}{n}, \text{ if }n>1\\  & =1, \text{ otherwise} \end{array}$

The order of this algorithm is

  1. $\log n$
  2. $n$
  3. $n^2$
  4. $n^n$
in Algorithms retagged by
by
1.4k views

1 comment

Using subsitution O(log n) therfore option A is correct
0
0

2 Answers

2 votes
2 votes
We can solve this by back substitution method.

T(n) = T(n-1)+1/n

T(n-1) = T(n-2) + 1/(n-1)

T(n-2) = T(n-3) + 1/(n-2)

........

After moving like this, final equation we get as:

T(n) = 1+1/2+1/3+1/4+1/5+.......+1/(n-2)+1/(n-1)+1/n

T(n) = logn

So A is the correct answer.
by
0 votes
0 votes
Using substitution method

O(Logn)
Answer:

Related questions