Text Practice Mode
Recursion - Function has call to itself.
created Yesterday, 16:51 by qasgon
1
251 words
119 completed
0
Rating visible after 3 or more votes
saving score / loading statistics ...
00:00
Any function can call itself. Further function can call itself if required. Such function is called as recursive function and this feature is called as recursion. The most important thing one should understand is when to use recursion. Using the recursion anywhere will cause the program complex as well as inefficient. Recursion is best suited for the cases, where some process can be explained in terms of itself in concepts like factorials, powers and Fibonacci, etc. Recursive function has to call itself. So when such function is called, the control will keep rotating into multiple calls of the same function. While writing such function. While writing such function care should be taken so that at certain time recursive execution of the function is stopped and control returns back to the calling function. Thus appropriate end condition must be written. Many times this end condition is defined in the process itself possibly as part of mathematical formula. For recursive factorial, one must remember that 0! = 1. If end condition is missing or condition is given wrong, then program would terminate abnormally. Writing a recursive program is always easy if the recursive formula and the end condition is well defined. Even the writing the function is easier, understanding the flow of execution is bit tedious due to recursive calls. Recursion works much similar to substitution method of mathematics. Substituting the result of each into the previous step starting from the last step will give the result. Recursion works in exactly same manner.
saving score / loading statistics ...