FoCS 202324 2
FoCS 202324 2
Science: Lecture 2
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
Recursion and Complexity
summing 3 0 ⇒ summing 2 3
Algorithms like this are
⇒ summing 1 5
⇒ summing 0 6
known as iterative or
⇒6 tail recursive
Recursion vs iteration
• Why two terms iterative and tail recursive?
• “Iterative” normally refers to a loop: e.g. coded using while.
• “Tail-recursion” involves the recursive function call being the last
thing that expression does.
2 2
E.g. simplify 3n + 34n + 433 → n
fi
fi
Facts about O notation