Comment on A Linear Algebra Trick for Computing Fibonacci Numbers Fast
cbarrick@lemmy.world 1 year agoThe article is comparing to the dynamic programming algorithm, which requires reading and writing to an array or hash table (the article uses a hash table, which is slower).
The naive algorithm is way faster than the DP algorithm.
t_veor@sopuli.xyz 1 year ago
It’s not that hard to check yourself. Running the following code on my machine, I get that the linear algebra algorithm is already faster than the naive algorithm at around n = 100 or so. I’ve written a more optimised version of the naive algorithm, which is beaten somewhere between n = 200 and n = 500.
Try running this Python code on your machine and see what you get:
Here’s what it prints on my machine:
cbarrick@lemmy.world 1 year ago
Nice.
I have successfully stuck my foot in my own mouth.