Loading topic
if statements and for loops, and read Big-O notation. It also builds on the two previous chapters: you should know what a base case and a recursive case are, and have a rough picture of the call stack.3 min readfactorial function from the previous chapter and that you have seen proof by mathematical induction at least once. Tracing a call stack shows that factorial(5) returns 120. It does not show that the function is right for every input. Induction give3 min readfactorial. It also assumes you know that each call gets its own stack frame on the call stack. The question here is what happens when the stack gets too deep.2 min readfactorial from earlier chapters and that you know Python raises RecursionError once the call stack gets too deep. You should also be comfortable tracing stack frames by hand.3 min readfib(n) takes exponential time because it recomputes the same subproblems over and over.2 min readfib and the memoized fib_memo from the previous chapters, along with Big-O notation.2 min read// and % operators.3 min read// and % operators and that floats are approximate. Here we extend fast_power so that it accepts negative exponents without losing its O(log n) behavior.2 min read% (remainder) operator and Big-O notation. The goal here is to compute x^n mod m when x^n itself is far too large to work with directly.2 min read