Efficient Fibonacci Algorithms

The cluster focuses on discussions of various methods to compute Fibonacci numbers efficiently, including matrix exponentiation for O(log n) time, closed-form Binet's formula, memoization, dynamic programming, and critiques of naive recursive implementations with exponential complexity.

📉 Falling 0.4x Programming Languages
1,841
Comments
20
Years Active
5
Top Authors
#6410
Topic ID

Activity Over Time

2007
3
2008
17
2009
45
2010
60
2011
135
2012
58
2013
139
2014
103
2015
123
2016
88
2017
65
2018
110
2019
146
2020
124
2021
112
2022
109
2023
154
2024
141
2025
104
2026
5

Keywords

eigenstate.org Node.js JS fastFibonacci.hs oranlooney.com en.m i.e wikipedia.org nayuki.io matrix log compute calculate multiplication numbers arithmetic implementation sequence algorithm

Sample Comments

ForHackernews Jul 15, 2020 View on HN

Fibonacci has a closed-form solution! Forget writing loops, you can write one damn equation. Runs in constant time.

willvarfar Dec 1, 2011 View on HN

You mean how fast can it compute fib(40) without memorization? ;)

fnord77 Mar 19, 2023 View on HN

that Fibonacci implementation has exponential complexity

Al-Khwarizmi Sep 28, 2018 View on HN

The "right" way to do Fibonacci is to use matrix multiplication to get the nth Fibonacci number in logarithmic time (google Fibonacci log n matrix).

bibanez Sep 10, 2022 View on HN

This isn't faster unless you diagonalize the matrix. Then you get the closed form for fibonacci

nicklovescode Jun 10, 2011 View on HN

I just ran it, fib is roughly six times faster

jergosh Mar 9, 2011 View on HN

aka "How not to implement Fibonacci sequence"

adestefan Oct 11, 2011 View on HN

Is this the next "how fast is Fibonacci" fiasco?

stevefan1999 Nov 5, 2019 View on HN

oh, fibonacci numbers, why do i take 10 seconds to figure it out

wapz Apr 26, 2017 View on HN

I was recently asked to calculate the fibonacci sequence value in an O(log n) time complexity. I had no clue how to do it and explained that I can solve it in O(N) easily but don't even know how to approach the O(log n) method. I knew there must be some trick using factors but didn't even know how to start the problem. I looked it up later and one of the ways is using matrix multiplication (an implementation I still wouldn't be able to do without seeing pseudocode).