edited by
7,555 views
5 votes
5 votes

The running time of an algorithm is given by:

                      $T(n) = T(n-1) + T(n-2) - T(n-3)$, if $n > 3$

                                  = $n$, otherwise

Then what should be the relation between $T(1), T(2), T(3)$, so that the order of the algorithm is constant?

  1. $T(1) = T(2) = T(3)$
  2. $T(1) + T(3) = 2T(2)$
  3. $T(1) - T(3) = T(2)$
  4. $T(1) + T(2) = T(3)$
edited by

3 Answers

13 votes
13 votes
For sufficiently large $n$,

$T(n) = Tn-1)+T(n-2) - T(n-3).$

If the order of the algorithm for which above recurrence is applicable for the time complexity, is a constant,

$T(n) = T(n-1)$.

$\implies T(n) = T(n) + T(n-2) - T(n-3)$

$\implies T(n-2) = T(n-3)$

Going like this, we must have $T(1) = T(2) = T(3)$ which is option A.

PS: Typo is obvious in the question.
7 votes
7 votes
T(n)=T(n-1)+T(n-2)-T(n-3) , n>3

else T(n)=n

T(1)=1

T(2)=2

T(3)=3

using option:-

A. false

B. 1*3 is not equal to 4

C. T(1)-T(3)=> 1-3= -2 not equal to 2

D. 1+2=3 i,e equal to T(3)

ans . is D
Answer:

Related questions

5 votes
5 votes
2 answers
1
Arjun asked Apr 22, 2018
4,622 views
Consider the following C code segmentint f(int x) { if(x<1) return 1; else return (if(x-1)+g(x)); } int g(int x) { if(x<2) return 2; else return (if(x-1)+g(x/2)); }Of the...
3 votes
3 votes
4 answers
2
Arjun asked Apr 22, 2018
2,144 views
The time complexity of computing the transitive closure of binary relation on a set of $n$ elements is known to be$O(n)$$O(n*\log(n))$$O(n^{\frac{3}{2}})$$O(n^{3})$
1 votes
1 votes
2 answers
3
1 votes
1 votes
1 answer
4
Arjun asked Apr 22, 2018
5,179 views
An array $A$ consists of $n$ integers in locations $A[0], A , \ldots A[n-1]$. It is required to shift the elements of the array cyclically to the left by $k$ places, wher...