DEV Community

Aleksei Berezkin
Aleksei Berezkin

Posted on • Updated on

A simple (?) task on algorithm complexity

Let me introduce you The Very Bad Fibonacci Implementation:

function fib(n) {
    if (n <= 1) {
        return 1
    }
    return fib(n - 2) + fib(n - 1)
}
Enter fullscreen mode Exit fullscreen mode

The first question is very simple:

Q1. What's wrong with this implementation and how to fix it?

I know it's too easy 😆 That's why here's another for you:

Q2. What's it complexity in terms of Big O? How to estimate and prove it?

Answers will be published soon ⏳

Happy brainstorming!

Discussion (0)