I am supposed to prove an algorithm by induction and that it returns 3n - 2n for all n >= 0. This is the algorithm written in Eiffel.
P(n:INTEGER):INTEGER;
do
if n <= 1 then
Result := n
else
Result := 5*P(n-1) - 6*P(n-2)
end
end
My understanding is that you prove it in three steps. Basis step, Inductive Hypothesis, and Proof of completeness. This is what I have currently.
Basis:
P(0) returns 0, and 30 - 20 = 0.
P(1) returns 1, and 31 - 21 = 1.
Inductive Hypothesis:
Assume P(k) returns 3k - 2k for 0 <= k < n.
Proof of completeness:
For n, P(n) returns 5(P(n-1)) - 6(P(n-2))
5(P(n-1)) - 6(P(n-2))
5(3n-1 - 2n-1) - 6(3n-2 - 2n-2) <- Based on inductive hypothesis
This is the part where I get stuck. How the hell am I supposed to reduce this to look like 3n - 2n?
3^n - 2^n
in the first place? – IVlad5*g(n-1) - 6*g(n-2)
? What isg
? – Grégoire C