CS-212L-Data Structures and Algorithms
CS-212L-Data Structures and Algorithms
CS-212L-Data Structures and Algorithms
Semester 3
Lab 2
Recursion
Processing steps:
Step 1: what is recursion?
Computer programming languages allow a module or function to
call itself. This technique is known as recursion. In recursion, a
function α either calls itself directly or calls a function β that in
turn calls the original function α. The function α is called
recursive function.
it is implemented in stack as :
fib(5)= fib(4) + fib(3)
= fib(3) + fib(2) + fib(2) + fib(1)
= fib(2) + fib(1) + fib(1) + fib(0) + fib(1) + fib(0) + 1
= fib(1) + fib(0) + 1 + 1 + 1 + 1 + 1 + 1
= 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1= 8
Step 4: Termination
root ____________
|\\
|\\
b1 ____ b2 b3
|\\|\
l1 l2 l3 l1 l2
Class activity
REFRENCES: