Lec 3
Lec 3
n n!
1 1 1 1
2 2×1 = 2 × 1! =2
3 3×2×1 = 3 × 2! =6
4 4×3×2×1 = 4 × 3! = 24
5 5×4×3×2×1 = 5 × 4! = 120
Example
Algorithm
Code
Difference between Recursion and Iteration
Property Recursion Iteration
Through base case, where there will When the termination condition for
Termination
be no function call. the iterator ceases to be satisfied.
Used when code size needs to be Used when time complexity needs to
Usage small, and time complexity is not an be balanced against an expanded
issue. code size.