Recursion
Recursion in computer science is a method where the solution to a problem depends on solutions for small instances of the same problem. The approach can be applied to many types of problems, and is one of the central ideas of computer science.
"The power of recursion is obviously the possibility to define an infinite set of objects by a finite statement. Similarly, an infinite number of calculations can be described by a finite recursive program, even if this program does not explicit repetition. "
Most high-level computer programming languages support recursion by allowing a function to call itself in the program text. Some functional programming languages do not define any looping constructs, but rely on recursion to repeatedly call code. computability theory has proven that these recursive only languages are mathematically equivalent to the imperative languages, which means they can solve the same types of problems, even without the typical control structures like "everything" and "for".
Recursive data types
Many computer programs to treat or to generate a quantity arbitrarily large amounts of data. Recursion is a technique to represent data whose exact size the programmer does not know: the programmer can specify these data with an essentially self-referential. There are two types of self-referential definitions: definitions and inductive Coinductive.
induced data set
Main article: recursive data type
A recursive definition of inductively defined data is showing how to build instances of data. For example, linked lists can be defined by induction (here using Haskell syntax):
data = ListOfStrings EmptyList | Cons String ListOfStrings
The above code specifies a list of channels to be either empty or a structure that contains a string and a list of strings. Self-reference in the definition used to build lists of any number (finite) strings.
Another example is the inductive definition of natural numbers (or non-negative integers):
A natural number is 1 or n +1, where n is an integer.
Similarly recursive definitions are often used to model the structure of expressions and statements in programming languages. Language designers often express grammars in syntax as the Backus-Naur, here for example a grammar, a language simple arithmetic expressions with multiplication and addition:
| (*
| (+
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home