737 views
1 1 vote
Base condition T(n) = 1

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

Then

After solving i got to this step ...how should i generalize now

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

1 Answer

Best answer
0 0 votes
T(n)=T(n-1)+n;

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

T(n-2)=T(n-3)+n-2;

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

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

T(n)=T(n-k) +n*k -(1+2+3....k);

now at k=n we get T(0)=1;

so T(n)=T(0)+n*n- (1+2+3....n);

we get n^2-n(n+1)/2

T(n)=O(n^2)
• selected by
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
1.2k
1.2k views
Mayankprakash asked Oct 31, 2018
1,219 views
I want to learn to find time complexity of the recurrence relation of an algorithm.Please suggest some good links or any gatetoverflow imp questions links to look as exam...
0 0 votes
1 answers 1 answer
554
554 views
0 0 votes
1 1 answer
340
340 views
vishnusainune asked Dec 30, 2025
340 views
A recurrence arises in the problem: Number of ways to tile a 3×n rectangle with 2×1 dominoes (dominoes can be placed vertically or horizontally). Let T(n)​ be this number...
0 0 votes
1 1 answer
343
343 views
nirmalkary asked Sep 18, 2025
343 views
What will be the time complexity of T(n)= 3T(n-1) +n a)Theta (3^n) or b)Theta (n*3^n)