7: Recursion#

Recursion is when there is repetition within the definition when something is defined in terms of itself. We have already seen one form of recursion where the definition of a node included another node: a node is a unit consisting of data (elements or values) and a node. A node is a recursive data structure, defined in terms of itself. Just as data can be defined recursively, so can methods.

A recursive method is a method that includes a call to itself in its definition. We typically use recursion as an alternative to loops for doing repetition. Sometimes the recursive solution is much easier to program than the equivalent loop.

Nested stacking dolls

Recursion Dolls