### Similar presentations

1-12 © 2010 Pearson Addison-Wesley. All rights reserved. Why does recursion make it easier to conceptualize a solution? 1-12 You can use recursion in place of iteration (looping) One or more simple cases of the problem have a straightforward, non-recursive solution By applying this redefinition process every time the recursive function is called, eventually the problem is reduced to simple cases, which are relatievely easy to solve.

1-13 © 2010 Pearson Addison-Wesley. All rights reserved. The efficiency of recursion 1-13 As stated at the beginning of the chapter, recursive solutions are less efficient than an iterative solution in terms of computer time due to overhead for the extra function calls. However, in many instances the use of recursion enables us to specify a very natural, simple solution to a problem that would otherwise be very difficult to solve. It is a very important and powerful tool in problem solving and programming.

1-14 © 2010 Pearson Addison-Wesley. All rights reserved. Simple case vs. terminating condition 1-14 Simple cases involve simple solutions that can be split up into very small prblems A terminating condition may consist of an if statement that evaluates a particular condition, n <= 1. When the terminating condition is true, the function is dealing with one of the problems simple cases. The most common problem with a recursive function is that it may not terminate properly (in case the terminating condition is not correct or incomplete.