Dynamic Programming21 sections · 916 units
Open in Course

Factorial - Problem Statement

Classic first recursion

Now you will compute n!n!, the product of all positive integers up to nn. For example, 5!=5×4×3×2×1=1205! = 5 \times 4 \times 3 \times 2 \times 1 = 120. You could use a loop, but factorial is perfect for recursion because it has natural structure: n!=n×(n1)!n! = n \times (n-1)!.

Every factorial depends on a smaller factorial. Before reading on, think about this: when should you stop computing? And why is a stopping point necessary?

unnamed (4) (1).jpg