Recursion: Difference between revisions
Mr. MacKenty (talk | contribs) |
Mr. MacKenty (talk | contribs) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
A simple definition: Recursion is the process of a subroutine calling itself. | A simple definition: Recursion is the process of a subroutine calling itself. | ||
== Example == | |||
== | <syntaxhighlight lang=python> | ||
def factorial(n): | |||
if n == 1: | |||
return 1 | |||
else: | |||
return n * factorial(n-1) | |||
</syntaxhighlight> | |||
== Recursion == | |||
Line 13: | Line 22: | ||
</html> | </html> | ||
== | == Another look at recursion == | ||
<html> | |||
<iframe width="560" height="315" src="https://www.youtube.com/embed/VrrnjYgDBEk" frameborder="0" allowfullscreen></iframe> | |||
</html> | |||
== | |||
< | |||
== Standards == | == Standards == | ||
Line 63: | Line 38: | ||
* [[Abstract data structures]] | * [[Abstract data structures]] | ||
== References == | == References == |
Revision as of 16:24, 6 March 2018
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[edit]
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)
Recursion[edit]
Another look at recursion[edit]
Standards[edit]
- Identify a situation that requires the use of recursive thinking.
- Identify recursive thinking in a specified problem solution.
- Trace a recursive algorithm to express a solution to a problem.