DEV Community

Aleksei Berezkin
Aleksei Berezkin

Posted on • Edited on

1

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!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs