Recursion

What Is the Difference Between Recursion and Recursive?

Recursion is the technique, and recursive describes something that uses it, such as a recursive function. Here is how to use each word in C++.

On this page
  1. The short answer
  2. Recursion as a noun
  3. Recursive as an adjective
  4. Recursively and recurse
  5. Recursive definitions in math
  6. A quick way to remember
  7. Summary

The short answer

Recursion is a noun for the technique: a function, or a definition, that refers to itself. Recursive is an adjective for something that uses recursion, such as a recursive function or a recursive definition. So a function uses recursion, and it is a recursive function.

Recursion as a noun

“Recursion” names the technique. A few examples:

  • Recursion can make a tree traversal short and clear.
  • Factorial is a classic example of recursion.
  • Some problems are easier to solve with recursion than with a loop.

Recursive as an adjective

“Recursive” describes the thing that uses the technique:

  • A recursive function calls itself.
  • A recursive data structure, such as a linked list or a tree, contains smaller copies of itself.
  • A recursive definition describes something in terms of a smaller version of itself.

Here is a recursive function in C++:

#include <iostream>

int sumTo(int n) {
    if (n == 0) {
        return 0;
    }
    return n + sumTo(n - 1);   // a recursive call
}

int main() {
    std::cout << sumTo(4) << "\n";  // prints 10
    return 0;
}

The function sumTo is a recursive function. The line that calls sumTo(n - 1) is a recursive call, and that call is where the recursion happens.

Recursively and recurse

Two related forms show up in programming writing too:

  • Recursively is an adverb: “The function works recursively, calling itself on smaller inputs.”
  • Recurse is a verb: “The function recurses on the left half of the array,” meaning it makes a recursive call on that half.

Recursive definitions in math

The same words are used in mathematics. The factorial can be defined recursively: 0! is 1, and for any number n above 0, n! is n times (n - 1)!. That definition is recursive, and a function that computes it is an example of recursion.

For a complete program that uses recursion, the walkthrough on what is recursion in C programming with an example is a good next step.

A quick way to remember

Use recursion for the technique as a whole, and recursive for the things that have the property. If you are describing a function that calls itself, call it a recursive function. If you are describing the approach a solution takes, say the solution uses recursion.

Summary

Recursion is the technique. Recursive is the adjective for things that use it. A recursive function is one that uses recursion, and the word recursion names the idea behind it.

The complete guide to recursion

Recursive Functions in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

How to Use cout in C++

Learn how to use cout in C++ to print text, numbers and variables, add new lines, and format output, with short complete examples you can compile and run.

cout 4 min read

Header Guards in C++

A header guard stops a header from being included twice in one source file. Learn how #ifndef and #pragma once work, with examples and common mistakes.

Header Guards 4 min read