Added general recursion and python recursion
parent
b44697ec5c
commit
94ff968814
@ -0,0 +1,15 @@
|
||||
# For what Recursion is, please check recursion
|
||||
|
||||
# Simple Factorial Python Recursion
|
||||
def factorial(n) :
|
||||
if n == 0 :
|
||||
return 1
|
||||
else :
|
||||
return n * factorial(n-1)
|
||||
|
||||
# Simple Greatest Common Divisor Recursion
|
||||
def gcd(x, y) :
|
||||
if y == 0 :
|
||||
return x
|
||||
else :
|
||||
return gcd(y, x%y)
|
@ -0,0 +1,11 @@
|
||||
# Recursion
|
||||
# Def: "...is a method where the solution to a problem depends on solutions to smaller instance of the same problem.." - wiki
|
||||
# TL;DR: a function that calls itself inside its body.
|
||||
|
||||
# Recursive programs - Pseduocode
|
||||
function factorial:
|
||||
input: integer n such that n >= 0
|
||||
output: n * (n-1) * (n-2) * ... * 1 = n!
|
||||
|
||||
1. if n is 0, return 1
|
||||
2. else, return ( n * factorial(n-1) )
|
Loading…
Reference in New Issue