This is the lecture note of CS61A - Lecture 20.
Measuring Efficiency
By measuring efficiency, we can understand how long our programs will take to run.
Let's review our first example of tree recursion.
1 | def fib(n): |
Memoization
Memoization is a useful technique for speeding up the running time of a program.
1 | def memo(f): |
Exponentiation
Let's look at another example.
- Implement the exponential function in two different ways, one of which is more efficient than the other.
Orders of Growth
1 | # Overlap |
Notation
Big-O describes the upper bound for the time it takes for a function to run.
Big-Theta desribes both a lower and a upper bound.
Space
Space, or memory, is another resource that get consumed by programs as they execute. So you need also worry about it.
Consumption of space is taken by values. It also gets taken up by frames, so you need to know how many frames exist because of different function calls in your program at the same time.
1 | def count_frames(f): |
🎃 You can learn CS61B and CS170 to get more details about efficiency.