Javatpoint Logo
Javatpoint Logo

C++ Program to Find Fibonacci Numbers using Matrix Exponentiation

In this article, we will discuss a C++ program to find Fibonacci numbers using Matrix.

Finding Fibonacci numbers by matrix exponentiation is an important technique that takes advantage of the strength of matrices to calculate Fibonacci sequences effectively. This strategy is very beneficial when working with huge Fibonacci numbers because it considerably reduces time complexity when compared to typical recursive or iterative approaches.

Fibonacci Numbers:

The Fibonacci sequence is a set of numbers in which each of them is the sum of the two numbers before it. The series begins with 0 and 1 and proceeds in the following order: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. The sequence known as Fibonacci is defined mathematically in the following manner:

fib(0)=0, fib(1)=1

fib(n)=fib(n-1)+fib(n-2) for n>1

Matrix Exponentiation Method:

The matrix exponentiation method effectively finds Fibonacci numbers by combining multiplication by a matrix and exponentiation. Instead of calculating Fibonacci numbers repeatedly, we can use a matrix equation to express the relationship between successive Fibonacci numbers.

Algorithm:

Example:

Output:

Fib(7) is 13

Complexity:

Time Complexity: O(logN)

Auxiliary Space: O(logN)







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA