Fibonacci: Iterative, recursion, memoization, Matrix exponentiation--NOT OPTIMAL OOP--Scared, ATH

Published: 07 October 2023
on channel: Think n' Code
195
4

#shorts
Problem statement: https://codeforces.com/gym/102644/pro...
Solution: https://github.com/Mourad-NOUAILI/cod...
------------------
Imagine that you task is to compute the n-th term of the Fibonacci sequence, where n is BTW 0 and 10^18.

You can implement a iterative brute force solution. In this case, for huge ns, you'll wait a long time before you see a result, because its time complexity is O(n),

The recursive solution is worst. Not only because its O(2^n) time complexity, also because the call stack overflow,

You can fixed with memoization, to reduce the time complexity to O(n), but the space complexity will be O(n) o_O Really...

The best way is to use matrix exponentiation. Hey, hey, the time complexity is reduce to O(log n) and the space complexity is constant.

If you want a deep explanations of these all stuffs, just let me know in comments :)


Watch video Fibonacci: Iterative, recursion, memoization, Matrix exponentiation--NOT OPTIMAL OOP--Scared, ATH online, duration hours minute second in high quality that is uploaded to the channel Think n' Code 07 October 2023. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 195 times and liked it 4 visitors.