Recursion can be a very useful technique to create elegant and maintainable code. This technique involves a method or lambda expression calling itself either directly or indirectly. While it may require more time and space than an equivalent iterative solution, in many situations, it will be a better solution if these expenses do not outweigh the benefits of using recursion.
Many data structures are recursive in nature. Such data structures are self-referencing. They have references within the structure to same structure. For example, a linked list node will have a reference to a linked list node such as to the next node in the list. We used a left and right node reference in our tree examples to illustrate a recursive data structure in several of our examples. Recursive data structures lend themselves to recursive solutions.
The recursion technique involves breaking a problem down into smaller units, making a recursive call and then combining the results. We demonstrated how to create...