File tree Expand file tree Collapse file tree 1 file changed +5
-15
lines changed
Expand file tree Collapse file tree 1 file changed +5
-15
lines changed Original file line number Diff line number Diff line change 11
22# coding: utf-8
33
4- # this is a test on how recursion with memory reduces time complexity
4+ #this is a test on how recursion with memory reduces time complexity
55
66#i need a global dictionary to do the memorization
77#or i can change function fib(n) into fib(n,mem)
@@ -25,8 +25,8 @@ def fib(n):
2525 mem [n ]= (fib (n - 1 )+ fib (n - 2 ))
2626 return mem [n ]
2727
28- #this is the fibonacci recursion function without memory
29- #it is basically algorithm 101 for any coding language
28+ #this is the fibonacci recursion function without memory
29+ #it is basically algorithm 101 for any coding language
3030def f (n ):
3131 if n == 1 :
3232 return 1
@@ -35,8 +35,8 @@ def f(n):
3535 else :
3636 return f (n - 1 )+ f (n - 2 )
3737
38- # i calculate how long these two functions take
39- #print out the comparison
38+ # i calculate how long these two functions take
39+ #print out the comparison
4040def compare (n ):
4141 t1 = dt .datetime .now ()
4242 f (n )
@@ -49,14 +49,4 @@ def compare(n):
4949 print ('recursion with memory: ' ,t2 - t1 )
5050
5151
52-
53-
54-
5552compare (20 )
56-
57-
58-
59-
60-
61-
62-
You can’t perform that action at this time.
0 commit comments