Recursion
Recursion refers to something being a part of its own definition.
Recursion refers to something being a part of its own definition.
Description
Usually, a recursive function refers to itself in some cases (or inputs), but not in every case. A function that referred to itself in every case would never terminate.
When a function refers to itself, it often uses a smaller input than the input it was given. In this way, it can solve a problem by first solving a simpler version of the problem.
Example
An example of a recursive function is:
- If then return .
- If then return .
This function computes the factorial of a natural number. It works because and .
The definition has two cases: a recursive case for , and a case for that is not recursive. The case that is not recursive is called a "base case".
Uses
Recursion can be used to write computer programs. A program that uses recursion may be easier to write and understand than a program that does the same thing without recursion.
Recursion is used in mathematics to prove theorems. This method is called induction.
The idea of recursion can be seen in art and language. For example:
- A fractal image contains smaller versions of itself.
- In the rules of grammar, a sentence can be part of another sentence.
Easter Eggs
In the Google search engine, if you type up "recursion", it will say "Did you mean: Recursion", a reference to the meaning of recursion.[1]
References
- ↑ "recursion - Google Search". www.google.com. Retrieved 2022-11-29.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.