Back to articles
Fibonacci Numbers Are Everywhere Once You Start Looking

Fibonacci Numbers Are Everywhere Once You Start Looking

via Dev.toMichael Lip

The Fibonacci sequence starts with 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144. Each number is the sum of the two before it. It sounds like a trivial math exercise until you realize this sequence appears in sunflower seed spirals, stock market analysis, data structure design, and even the way your screen lays out content. I want to walk through why this sequence matters beyond textbook examples and where you will actually encounter it as a developer. The naive implementation teaches you recursion Every CS course starts here: function fib ( n ) { if ( n <= 1 ) return n ; return fib ( n - 1 ) + fib ( n - 2 ); } This is elegant and also terrible. The time complexity is O(2^n). Computing fib(40) makes over a billion function calls. Computing fib(50) will hang your browser tab. The reason is that the function recomputes the same values exponentially many times. fib(5) computes fib(3) twice. fib(6) computes fib(3) three times. By fib(40) , the waste is astronomical. Memoization turns it int

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles