2.2 Recursive techniques
Iterative loop
A sequence if statements which are repeated without jumping out of loop e.g. FOR loop
Recursive loop
A function which calls itself to produce a looping effect.
e.g 4 Factorial = 4 x 3 x 2 x 1
Base case stops series of function calls stopping the infinite loop.
An infinite loop results in a stack overflow error
General case- recursion part
The role of the stack
the stack stores the return addresses of functions or procedures which are calls recursively.
The stack is LIFO- (Last In First Out) so as the function reaches their end return addresses are returned to the correct function
No comments:
Post a Comment