Recursion: Difference between revisions
Mr. MacKenty (talk | contribs) (Created page with "right|frame|Programming basics<ref>http://www.flaticon.com/</ref> Recursion in computer science is a method where the solution to a problem depends on sol...") |
Mr. MacKenty (talk | contribs) |
||
(6 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 == | |||
== | <html> | ||
<iframe width="560" height="315" src="https://www.youtube.com/embed/t4MSwiqfLaY" frameborder="0" allowfullscreen></iframe> | |||
</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 61: | Line 38: | ||
* [[Abstract data structures]] | * [[Abstract data structures]] | ||
== References == | == References == |
Revision as of 15: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.