Skip to main content

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.

BasisNormal (non-recursive) functionRecursive function
CallingCalled by other functions, never by itselfCalls itself (directly or indirectly)
TerminationEnds after its statements runNeeds a base case, else infinite recursion
RepetitionUses loops (for, while)Repetition by repeated self-calls
MemoryOne stack frame per callMany frames at once; stack overflow possible
SpeedUsually fasterUsually slower (call overhead)
CodeCan be longer for some problemsShort and clear for tree, TOH, factorial type problems
Examplesum = a + b;fact(n) = n * fact(n-1)

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 5 questions →