- 2075 Baisakh · 3 marks
Normal vs recursive function
Short answer
A normal function is called by others and uses loops for repetition, while a recursive function calls itself, requires a base case, and uses the call stack for repetition. Recursion may be slower and use more memory but simplifies code for problems like tree traversal.
Distinguish between normal function and recursive function.
| Basis | Normal (non-recursive) function | Recursive function |
|---|---|---|
| Calling | Called by other functions, never by itself | Calls itself (directly or indirectly) |
| Termination | Ends after its statements run | Needs a base case, else infinite recursion |
| Repetition | Uses loops (for, while) | Repetition by repeated self-calls |
| Memory | One stack frame per call | Many frames at once; stack overflow possible |
| Speed | Usually faster | Usually slower (call overhead) |
| Code | Can be longer for some problems | Short and clear for tree, TOH, factorial type problems |
| Example | sum = a + b; | fact(n) = n * fact(n-1) |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Is recursion slow; recursive vs non-recursive · Data Structure and Algorithm, chapter 5
- Recursion; iterative vs recursive choice · Data Structure and Algorithm, chapter 5
- Recursive function and how it works · Computer Programming, chapter 6 · asked 3×
- Rolled vs normal concrete; CC pavement construction · Transportation Engineering II, chapter 3
- Standard normal: definition, properties, importance · Probability and Statistics, chapter 3 · asked 2×
- Marconi transmitter, mobile vs nomadic, Telecom Act · Telecommunications, chapter 1