The example I gave may seem overwhelmingly confusing and inefficient. Don’t worry about confusion – it goes away very quickly with practice. Recursion becomes so intuitive that you will begin to naturally think of recursive solutions rather than the iterative ones which you are probably familiar with. As for efficiency, there are various optimization techniques which many modern programming languages (especially functional programming langauges) employ to make recursion more efficient. I will also demonstrate later the fact that there are problems which have no obvious iterative solution!
There are a few compelling reasons to use recursion – the first is elegance. A recursive solution will often describe the nature of a problem much better than the relatively artificial looping constructs such as for and while can. The second reason for using recursion is because in many functional programming languages, it is the only way to perform the same operations as one would using iteration.
When dealing with recursive data structures such as trees and lists, the need for the use of recursion becomes very clear – it is both the most intuitive and the simplest way of dealing with recursive data structures!