From 0a4066baf26fad742d25cff7ad2519fd1c865176 Mon Sep 17 00:00:00 2001 From: Oliver Payne Date: Tue, 17 May 2022 22:07:04 +0100 Subject: [PATCH] Add notes for 3.27 --- notes.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/notes.txt b/notes.txt index 7a8339d..87636eb 100644 --- a/notes.txt +++ b/notes.txt @@ -116,3 +116,18 @@ For z as in the example, (sqrt (+ (square 3) (square 4))) 5 + +3.27 + +For i = 0 or 1, (memo-fib i) is O(1). For i > 1, it is n additions. This is because +for each i, (memo-fib i) is only calculated once. This calculation is O(n) and each subsequent +lookup is O(1). So, even though (memo-fib i) is called multiple times for each i, only i additions are +done for each. + +This scheme will not work if we use (define memo-fib (memoize fib)). The fib procedure is +defined recursively in terms of itself, and each of the these recursive calls will be evaluated in +an environment whose enclosing environment is the global environment. This explicitly does not include +the table of pre calculated results, so we will not get the benefit of this. Defining memo-fib recursively +in terms of itself means that the recursive calls are evaluated in an environment whose enclosing +environment is one where memoize has been evaluated, and thus it contains the table. This is critical +to make the memoization work as required.