70 likes | 77 Views
This presentation on Recursion in C will help you understand one of the most important aspects of Programming ie. Recursion. Understand how to create a Recursive Function.<br><br>1. What is Recursion?<br>2.u200b Working of Recursion<br>3.u200b Types of Recursion<br>4.u200b Advantages and Disadvantages<br><br>Learn more at: https://www.simplilearn.com/pgp-full-stack-web-development-certification-training-course?utm_campaign=C &utm_medium=Description&utm_source=Slideshare<br>
E N D
What’s in it for you ? What is Recursion ? Working of recursion Types of recursion Advantages and Disadvantages
What is Recursion ? Syntax : Void recursion() { recursion(); } Int main() { recursion(); } A function calling itself again and again until a certain condition is met is known as recursion
Working of recursion Factorial of 5 : return 5*factorial(4) = 120 return 4*factorial(3) = 24 return 3*factorial(2) = 6 return 2*factorial(1) = 2 return 1*factorial(0) = 1 Recursion performs repetition on the function calls and it stops the execution when the base case becomes true. A base condition should be defined in the recursive function To understand this let’s take an example
Types of recursion Direct recursion Indirect recursion When a function calls itself indirectly from other function then this type of recursion is called Indirect recursion Example : When a function calls itself directly then it is known as a direct function Example : void recursion( ) { recursion(); } void sub() { recursion(); } void recursion() { sub(); }
Advantages and Disadvantages • The recursive program has greater space requirements than the iterative program • It also has greater requirement of time because of function calls • it provides a simple and clean way to write a code • Recursion is more preferred in problems like tree traversals, tower of Hanoi, Advantages Disadvantages