Recursion

From Computer Science Wiki
Jump to: navigation, search
Programming basics[1]

Recursion in computer science is a method where the solution to a problem 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 [2]

A simple definition: Recursion is the process of a subroutine calling itself.

Example

def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)

Recursion

Another look at recursion


Standards

  • IdentifyProvide an answer from a number of possibilities. Recognize and state briefly a distinguishing fact or feature. a situation that requires the use of recursive thinking.
  • IdentifyProvide an answer from a number of possibilities. Recognize and state briefly a distinguishing fact or feature. recursive thinking in a specified problem solution.
  • TraceFollow and record the action of an algorithm. a recursive algorithm to express a solution to a problem.

See Also

References