Is there a faster way to compute the nth Fibonacci number than by fib2? Hint: one idea involves matrices.
We start by writing the equation F₁ = F₁ and F₂ = F₀ + F₁ in matrix notation:
Similarly [F₁] = [0. 1.] [F₀]
[F₂]. [1 1.]. [F₁]
[F₂] = [0. 1.]. [F₁]
[F₃]. [1. 1.] [F₂]
= [0. 1]² [F₀]
[1. 1]. [F₂]
and in general
[Fₙ] = [0. 1.]ⁿ .[F₀]
[Fₙ₊₁] [1. 1.] [F₁]
So, in order to computer Fₙ, it suffices to raise this 2 x 2 matrix, call it X to the nth power.
a. Show that two 2 x 2 matrices can be multiplied using 4 additions and 8