AoPSWiki
Art of Problem Solving's olympiad training program WOOT starts on Septebmer 8. Train with the top high school students in the the world! Click here to enroll today!

Recursion

From AoPSWiki

Recursion is a method of defining something (usually a sequence or function) in terms of previously defined values. The most famous example of a recursive definition is that of the Fibonacci sequence. If we let be the th Fibonacci number, the sequence is defined recursively by the relations and . (That is, each term is the sum of the previous two terms.) Then we can easily calculate early values of the sequence in terms of previous values: F_0=1, F_1=1, F_2=2, F_3=3, F_4=5, F_5=8, and so on.

Often, it is convenient to convert a recursive definition into a closed-form definition. For instance, the sequence defined recursively by and for also has the closed-form definition .

In computer science, recursion also refers to the technique of having a function repeatedly call itself. The concept is very similar to recursively defined mathematical functions, but can also be used to simplify the implementation of a variety of other computing tasks.


Examples

See also

Want to learn how to tackle those tough AMC/AIME/Olympiad counting and probability problems? Check out Art of Problem Solving's NEW Intermediate Counting & Probability by David Patrick.
© Copyright 2007 AoPS Incorporated. All Rights Reserved. • FoundationPrivacyContact Us