Reputation: 12022
I am trying to find the Nth Fibonacci number in O(logn) time. We can do O(logn) solution by using the Fibonacci Q matrix.
But, there is another solution by using the Cassini and Catalan identities to find the Nth Fibonacci number in O(logn) time. It states below:
If n is even then k = n/2: F(n) = [2*F(k-1) + F(k)]*F(k)
If n is odd then k = (n + 1)/2: F(n) = F(k)*F(k) + F(k-1)*F(k-1)
I could understand the proof only upto the marked equation:
But, I am not understanding the below equations and the final derived equations.
Can anyone please explain in details? Thanks in Advance.
Upvotes: 1
Views: 1227
Reputation: 372784
I believe the idea is to take this matrix product
|1 1|^n |1 1|^m |1 1|^{m+n}
|1 0| x |1 0| = |1 0|
and use the fact that this can be rewritten as
|F_{n+1} F_n | |F_{m+1} F_m | |F_{m+n+1} F_{m+n} |
| | x | | = | |
|F_n F_{n-1}| |F_m F_{m-1}| |F_{m+n} F_{m+n-1}|
Now, multiply the matrices on the left using the standard matrix product formula. You get this reuslt:
|F_{n+1} F_{m+1} + F_n F_m F_{n+1}F_m + F_n F_{m-1} | |F_{m+n+1} F_{m+n} |
| | = | |
|F_n F_{m+1} + F_{n-1} F_m F_n F_m + F_{n-1} F_{m-1} | |F_{m+n} F_{m+n-1}|
This gives these four equations:
The remaining equalities fall out from just substituting in specific values of m and n.
Upvotes: 1