Skip to content

Commit 09d11b0

Browse files
authored
External caching in fibonacci function
Refactored fibonacci function to use a cache for improved performance.
1 parent facef1e commit 09d11b0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sprint-2/improve_with_caches/fibonacci/fibonacci.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
def fibonacci(n, cache={}):
1+
cache={}
2+
3+
def fibonacci(n):
24
'''Adding a dictionary to store a copy of what we have already calculated, the complexity becomes linear.
35
With the cache, each value is computed once, bringing it down to O(n)
46
'''

0 commit comments

Comments
 (0)