File tree 1 file changed +5
-15
lines changed
1 file changed +5
-15
lines changed Original file line number Diff line number Diff line change 1
1
2
2
# coding: utf-8
3
3
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
5
5
6
6
#i need a global dictionary to do the memorization
7
7
#or i can change function fib(n) into fib(n,mem)
@@ -25,8 +25,8 @@ def fib(n):
25
25
mem [n ]= (fib (n - 1 )+ fib (n - 2 ))
26
26
return mem [n ]
27
27
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
30
30
def f (n ):
31
31
if n == 1 :
32
32
return 1
@@ -35,8 +35,8 @@ def f(n):
35
35
else :
36
36
return f (n - 1 )+ f (n - 2 )
37
37
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
40
40
def compare (n ):
41
41
t1 = dt .datetime .now ()
42
42
f (n )
@@ -49,14 +49,4 @@ def compare(n):
49
49
print ('recursion with memory: ' ,t2 - t1 )
50
50
51
51
52
-
53
-
54
-
55
52
compare (20 )
56
-
57
-
58
-
59
-
60
-
61
-
62
-
You can’t perform that action at this time.
0 commit comments