COMP90038 Algorithms and Complexity: Recursion
COMP90038 Algorithms and Complexity: Recursion
COMP90038 Algorithms and Complexity: Recursion
Recursion
Michael Kirley
Lecture 6
Semester 1, 2017
But there are also examples of, say, array-processing algorithms that
are naturally recursive.
function Fib(n)
if n = 0 then
return 1
if n = 1 then
return 1
return Fib(n − 1) + Fib(n − 2)
Of course we can only move some top-most disk to the top of some
pile. Nevertheless the solutions is conveniently expressed recursively,
saying how to solve the task for n desks, assuming we first solve the
problem for n − 1:
Now we have two sub-problems to solve, but each is smaller than the
original problem!
Usually that’s the easy part, but here they are harder to determine
than what the recursive case looks like!
Its running time grows exponentially as you grow the input amount.