in Algorithms edited by
7,504 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)$
in Algorithms edited by
by
7.5k views

2 Comments

option B is correct.
0
0
edited by

Refer: https://gateoverflow.in/18927/the-running-time-of-an-algorithm-is-given-by-t-1-t-n-2-t-n-3-if-n%26gt

The above will give you a description that any value will give you a value of O(n)

 

This we will get any value as O(n) so all three T(1),T(2) and T(3) will have  O(n) so

 T(1)=T(2)=T(3)  as all will have o(n) only as that is the more concise answer

SO OPTION A IS CORRECT

 

0
0

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.
by

3 Comments

Sir, where is typo.. I didnt understand
0
0
SIr can you explain what's the problem in this question and what is the correct solution
0
0
Why are we considering sufficiently large $n$ when we have to find relation between $T(1)$, $T(2)$ and $T(3)$? Doesn't the base condition says $T(n) = n$ when $n\ngtr 3$>?
1
1
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

2 Comments

edited by
I thought B and D are correct.

B. 1+3=2×2
D. 1+2=3

But reading the question again, t1 t2 t3 are equal as all of them will be of the order of O(1) . We dont have to take their values literally.
3
3
@sonveer tomar 1,Consider for urself when all the options are solved by substituting the values we have the following answer:-

For option  b)

1+3=2*2

For option c)

1-3=2

For option d) 1+2=3

3=3. Now you tell why option d) is not right?It is also giving a constant value as answer
0
0
0 votes
0 votes
Answer:

Related questions