Recursion function:
- It is one of the most powerful tools in the programming language.
- It is a process where function calls itself again and again.
- Recursion basically divides the big problem into small problems up to the point where it can be solved easily.
Condition for Implementing Recursion:
- It must contain base condition i.e. at which point recursion will end Otherwise it will become infinite.
- It takes more memory as compare to LOOP statement because with every recursion call memory space is allocated for local variables.
- It is less efficient in terms of speed and execution time
- Suitable for complex data structure problems like TREE, GRAPH, etc
Example program:
Output:
No comments:
Post a Comment