Recursion

Abstract

Up to now, we have not use recursion in our examples. Instead we devote a special chapter to this important programming technique. Recursion can be very useful and convenient, and in some cases recursive solutions are much shorter and nicer than non-recursive ones.

We start with simple examples (section 7.1) to illustrate how recursive programs work. Then (section 7.2) we consider a class of problems where recursion is especially useful (tree processing). In section 7.3 we return to the problems considered in chapters 2 and 3 and show how they can be solved using recursion. Some other examples (topological sorting, finding connected components, etc.) are consideredin section 7.4.