Upcoming SlideShare
×

C-18

239 views

Published on

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
239
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
10
0
Likes
1
Embeds 0
No embeds

No notes for slide

C-18

1. 1. Lecture 18 Version 1.0 Recursion
2. 2. 2 Rushdi Shams, Dept of CSE, KUET, Bangladesh What is Recursion  A function is called ‘recursive’ if a statement within the body of a function calls the same function  Sometimes called ‘circular definition’
3. 3. 3 Rushdi Shams, Dept of CSE, KUET, Bangladesh Iteration
4. 4. 4 Rushdi Shams, Dept of CSE, KUET, Bangladesh Recursion
5. 5. 5 Rushdi Shams, Dept of CSE, KUET, Bangladesh Explanation
6. 6. 6 Rushdi Shams, Dept of CSE, KUET, Bangladesh More Simpler Recursion
7. 7. 7 Rushdi Shams, Dept of CSE, KUET, Bangladesh And the classical problem
8. 8. 8 Rushdi Shams, Dept of CSE, KUET, Bangladesh Iteration vs Recursion  1. Both iteration and recursion are based on control structure. Iteration uses a repitation structure and recursion uses a selection structure.  2. Both involves in a termination state checking.  3. Both can be run infinitely. (which is of course not desirable)  4. Recursion is expensive in case of memory and processing time than iteration.  5. Recursion for many cases makes programs easier.  6. Recursion is the style of stylish programmer. 