Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm confused by the corrected diff in the README... isn't that cache recreated on each function call to fib(), making the cache pointless?


It is recreated on every call to `fib`, but the `_fib`s get to reuse it. Using a cache makes `_fib` O(N) to compute, so it gives a performance benefit as long as you aren't calling `fib(n)` with very small values of `n`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: