Recursion
used to replace loops.
Recursive defined
data structures, like lists, arevery well-suited to processing by recursiveprocedures and functions
recursive procedure
mathematically moreelegant than one using loops
Repetitive algorithm
a process wherby asequence of operations is executed repeatedlyuntil certain condition is achieved.
Repetition can be implemented using loop
while, for or do..while.
Recursive is a repetitive process in which an
algorithm calls itself.
Recursive drawback
Execution running time for recursivefunction is not efficient compared to loop, sinceevery time a recursive function calls itself, itrequires multiple memory to store the internaladdress of the function.
2 parts of recursive
BASE CASE(S), RECURSIVE CASE(S
BASE CASE(S
case(s) so simple that theycan be solved directly
RECURSIVE CASE(S)
more complex – makeuse of recursion to solve smaller subproblems & combine into a solution to the larger problem
Base case rules
There is one or moreterminal cases whereby the problem will be solvedwithout calling the recursive function again.
general case rules
recursive call byreducing the size of the problem
Important factors for recursive implementation
• There’s a condition where the function will stopcalling itself. (if this condition is not fulfilled,infinite loop will occur)• Each recursive function call, must return to thecalled function.• Variable used as condition to stop the recursivecall must change towards terminal case.