Data Structures

1: 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.  
A.

n

B.

log n

C.

nn

D.

n2

 

Answer : A

Explanation :

Let us find what is T(4), T(5), T(6) is.
T( 4) = T(3) + T(2) - T(1) = 3 + 2 - 1 = 4
T(5) = T(4) + T(3) - T(2) = 4 + 3 - 2 = 5
T(6) = T(5) + T(4) - T(3) = 5 + 4 - 3 = 6
By induction it can be proved that T(n) = n. Hence order is n.

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.