Skip to main content
Engineering LibreTexts

18: Recursion

  • Page ID
    54227
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The Google search result for recursion, shows Recursion, did you mean recursion?

    Recursion is a powerful general-purpose programming technique and is used for some important applications including search and sorting methods. Recursion is the idea that a function may call itself (which is the basis for the joke).

    Recursion can be very confusing in its simplicity and power. The examples in this section will not be enough in themselves for the reader to obtain recursive enlightenment. The goal of this section is to provide an introduction to the concept on recursion. The simple examples here, which are used introduce recursion, are meant to help demonstrate the form and structure for recursion. More complex examples (than will be discussed here) should be studied and implemented in order to ensure a complete appreciation for the power of recursion.

    The calling process previously described supports recursion without any changes. A recursive routine must have a recursive definition that includes:

    1. base case, or cases, that provide a simple result (that defines when the recursion should stop).

    2. rule, or set of rules, that reduce toward the base case.

    This recursive definition is referred to as a recursive relation.


    This page titled 18: Recursion is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?