CS2
Recursion
2
Concept of Recursion
nWe have already seen that a method in a class can call other methods, either in the same or other classes
n• However a method in a class can also call itself
n• This self-referential behavior is known as recursion
n• Recursion is an extremely powerful technique for expressing certain complex programming tasks, as it provides a very natural way to decompose problems n• Despite this, there are costs associated with recursion and the careful programmer will always be aware of these
n