Recursion

noun

say it: “rih-KUR-zhun” /rɪˈkɜrʒən/

Solving a problem by having a function call itself on a smaller piece of the same problem, until the piece is small enough to answer at once.

What is recursion?

Recursion is solving a problem by having a function call itself on a smaller piece of the same problem, like counting a set of nesting dolls by opening one and counting the dolls inside it the same way. Every recursive function has a base case, answered straight away, and a recursive case, which calls the function again.

In a sentence

  • “I counted the nested folders with recursion: the function adds up one folder, then calls itself for each folder inside.”

Level: Apprentice · More Data Structures terms at this level

Updated

In other subjects