Tag Archives: recursive

What is recursion or recursive?


Recursion or recursive

Recursion in computer science is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem (as opposed to iteration). The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.

The power of recursion or recursive evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions

As opposed to Iteration (a loop with a fixed size), recursion is not limited to a fixed size. Recursion can be best explained as a function calling itself. The classical example is recursion trough a FileSystem. This works as follows:

  1. Start at the top (‘C:/’ or ‘/’)
  2. Go to the next file;
  3. Is this a directory or file?
  4. In case of a directory -> Start over from the current directory, in case of a file-> Do something (like indexing)

This (simple) example traverses trough the whole File System.

A good and working example can be found in this article.