Recursion lets us write the Fibonacci numbers almost exactly how the math defines them:
fib <- function(n) {
if (n <= 1) {
return(n)
}
return(fib(n-1) + fib(n-2))
}
It’s elegant, but every call spawns two more calls, and the same values get recomputed over and over.
Question: How fast does the running time grow as \(n\) increases, and can we estimate that growth rate from noisy timing data?
- Theory makes a precise prediction (next slide).
- Real runtimes are noisy: background processes, memory, caching.
- Statistics lets us estimate the growth rate and put a confidence interval on it.