Make the fib function faster
Closed this issue · 2 comments
osmium-dev-old commented
Problem
The fib function time complexity is O(n) but I want to make it O(Log n)
How
Using the Fibonacci nth term formula :
if n is postive:
(phi^n) / sqrt(5)
if n is negative
((-phi)^(-n)) / sqrt(5)
Complexity
Time
Because of the Pow function the time complexity is Logarithmic -> O(Log n)
Space
Constant -> O(1)
osmium-dev-old commented
May I make this change?
Shuvro-d commented
Thanks for your suggestion. I will update it.