# Difference between revisions of "Recursion"

From Conservapedia

JamesWilson (Talk | contribs) (revert to last real revision) |
|||

Line 1: | Line 1: | ||

− | '''Recursion''' is a technique whereby a [[function]], in order to accomplish a task, calls itself to accomplish part of the task. | + | '''Recursion''' is the repeated application of a procedure or definition. |

+ | |||

+ | ===In Computing=== | ||

+ | |||

+ | Recursion is a technique whereby a [[function]], in order to accomplish a task, calls itself to accomplish part of the task. | ||

Every recursive solution involves two major parts or cases, the second part having three components: | Every recursive solution involves two major parts or cases, the second part having three components: | ||

Line 13: | Line 17: | ||

:1. Write a function to compute the sum of all numbers from 1 to n. | :1. Write a function to compute the sum of all numbers from 1 to n. | ||

:2. Write a function to compute 2 to the power of a non-negative integer. | :2. Write a function to compute 2 to the power of a non-negative integer. | ||

− | :3. Write a function to compute any number to the power of a non-negative integer. | + | :3. Write a function to compute any number to the power of a non-negative integer. |

+ | |||

+ | ===In Language=== | ||

+ | |||

+ | Recursion in language enables phrases to be embedded within one another, usually through [[conjunctions]], such that it should be possible to make an infinitely long sentence. For one such example we could take the sentence ''Many atheists are overweight'' and precede it with ''<person> said that'' indefinitely, as follows: ''Blaine said that Barbie said that Ken said that many atheists are overweight.'' | ||

[[Category:Computer Science]] | [[Category:Computer Science]] |

## Revision as of 21:47, 30 January 2013

**Recursion** is the repeated application of a procedure or definition.

### In Computing

Recursion is a technique whereby a function, in order to accomplish a task, calls itself to accomplish part of the task.

Every recursive solution involves two major parts or cases, the second part having three components:

- base case(s), in which the problem is simple enough to be solved directly, and
- recursive case(s). A recursive case has three components:

- 1. divide the problem into one or more simpler or smaller parts of the problem,
- 2. call the function (recursively) on each part, and
- 3. combine the solutions of the parts into a solution for the problem.

These exercises are useful to see examples of recursion:

- 1. Write a function to compute the sum of all numbers from 1 to n.
- 2. Write a function to compute 2 to the power of a non-negative integer.
- 3. Write a function to compute any number to the power of a non-negative integer.

### In Language

Recursion in language enables phrases to be embedded within one another, usually through conjunctions, such that it should be possible to make an infinitely long sentence. For one such example we could take the sentence *Many atheists are overweight* and precede it with *<person> said that* indefinitely, as follows: *Blaine said that Barbie said that Ken said that many atheists are overweight.*