Recursive definitions
Introduction / Definition
A recursive definition describes a result in terms of a smaller instance of itself. It needs a base case and a recursive rule that moves toward that case. Recursion mirrors many mathematical and structural definitions. Correct termination is essential.
Syntax / Structure / Formula
f(base)=result; f(n)=combine(n,f(smaller))
Detailed Explanation
For factorial, 0!=1 and n!=n×(n−1)! for n>0. The argument decreases until zero.
Example
Example: 5! = 5×4×3×2×1.
Output / Result
The result is 120.
Important Points / Notes
- Base case is essential.
- Each recursive step should progress toward it.
Mini Practice Question
Write a recursive definition for sum(1..n).
CheckpointTest Yourself