f(0) = 0;
f(1) = 1;
f(2) = 4;
f(n) = 2 f(n-1) - f(n-2) + 2; n > 2
A recursive algorithm would look like this and you can now implement it in any desirable language :-
function (n)
if n == 0
return 0
elif n == 1
return 1
elif n == 2
return 4
else:
return 2 + 2function(n-1) - function(n-2)
if you have any doubt you can ask in a comment section.Thums up the ans
Get Answers For Free
Most questions answered within 1 hours.