Why do we need Matrix exponentiation?
Let us consider the case for fibonacci series..!!
f(n) = f(n-1) + f(n-2)
1, 1, 2, 3, 5, 8, 13..........
But what if we need to find f(n) in which n
can be up to
Why do we need Matrix exponentiation?
f(n) = f(n-1) + f(n-2)
1, 1, 2, 3, 5, 8, 13..........
But what if we need to find f(n) in which n
can be up to
O(n) solution will not work here we need to find a better approach.
Thats where matrix exponentiation comes in!!!!
Concept
Before entering the core algorithm : Let us understand some basics for matrix
Concept
Before entering the core algorithm : Let us understand some basics for matrix
Matrix multiplication :
Concept
Before entering the core algorithm : Let us understand some basics for matrix
Matrix multiplication :
(n,t) X (t,m)
(n,m)
Concept
Before entering the core algorithm : Let us understand some basics for matrix
Matrix multiplication :
(n,t) X (t,m)
(n,m)
n
t
t
m
n
m
X
=
Concept
Before entering the core algorithm : Let us understand some basics for matrix
Concept of exponentiation :
Concept
Before entering the core algorithm : Let us understand some basics for matrix
Concept of exponentiation :
Suppose we have a matrix A.
Then
= A * A * A..........(t- times)
Steps for Matrix exponentiation
Consider a function
f(n) = f(n-1) + f(n-2)
Steps for Matrix exponentiation
Consider a function
f(n) = f(n-1) + f(n-2)
Recursively
Dynamic programming
Exponential
O(n)
Steps for Matrix exponentiation
States of function
f(n-1)
f(n-2)
f(n) = f(n-1) + f(n-2)
Kth state
(K+1)th state
f(n)
f(n-1)
Steps for Matrix exponentiation
States of function
f(n) = f(n-1) + f(n-2)
Kth state
(K+1)th state
M *
Steps for Matrix exponentiation
States of function
f(n) = f(n-1) + f(n-2)
Kth state
(K+1)th state
M *
The main game is to find this matrix
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
Kth state
(K+1)th state
M *
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
2X1
2X1
M *
Size of matrix
2X2
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
a*f(1) + b*f(0) = f(2)
c*f(1) + d*f(0) = f(1)
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
a*f(1) + b*f(0) = f(2)
c*f(1) + d*f(0) = f(1)
We get
a = 1 and b = 1
c = 1 and d = 0
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
a*f(1) + b*f(0) = f(2)
c*f(1) + d*f(0) = f(1)
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
Ultimately we need to get f(2)
f(0) = 1
f(1) = 1
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
Ultimately we need to get f(2)
f(0) = 1
f(1) = 1
1*f(1) + 1*f(0) = f(2)
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
Ultimately we need to get f(2)
f(0) = 1
f(1) = 1
1*1+ 1*1 = f(2)
Steps for Matrix exponentiation
States of function
f(2) = f(1) + f(0)
*
Ultimately we need to get f(2)
f(0) = 1
f(1) = 1
1*1+ 1*1 = f(2)
f(2) = 2
Steps for Matrix exponentiation
States of function
f(3) = f(2) + f(1)
*
f(0) = 1
f(1) = 1
*
M
Steps for Matrix exponentiation
States of function
f(3) = f(2) + f(1)
*
f(0) = 1
f(1) = 1
*
Steps for Matrix exponentiation
States of function
f(3) = f(2) + f(1)
*
f(0) = 1
f(1) = 1
*
*
Steps for Matrix exponentiation
States of function
f(3) = f(2) + f(1)
*
f(0) = 1
f(1) = 1
*
3-1 = 2
Steps for Matrix exponentiation
States of function
f(3) = f(2) + f(1)
*
f(0) = 1
f(1) = 1
*
2
Steps for Matrix exponentiation
States of function
f(n) = f(n-1) + f(n-2)
*
M
n-1
Steps for Matrix exponentiation
States of function
f(n) = f(n-1) + f(n-2)
*
M
n-1
M[0][0] * 1 + M[0][1] * 1
Some examples
States of function
f(n) = A*f(n-1) + B*f(n-2)
Some examples
States of function
f(n) = A*f(n-1) + B*f(n-2)
*
M
n-1
Some examples
States of function
f(n) = A*f(n-1) + B*f(n-2)
*
M
n-1
Some examples
States of function
f(n) = A*f(n-1) + B*f(n-2) + C
Some examples
States of function
f(n) = A*f(n-1) + B*f(n-2) + C
*
M
n-1
Some examples
States of function
f(n) = A*f(n-1) + B*f(n-2) + C
*
M
n-1
Some examples
States of function
f(n) = f(n-1) + f(n-4)
Some examples
States of function
f(n) = f(n-1) + f(n-4)
*
M
n-1
Some examples
States of function
f(n) = f(n-1) + f(n-4)
*
M
n-1