recursion Flashcards
1
Q
recursion
A
a function that repeatidly calls itself until a base case is met
provides an elegant (code is very simple and minimal) way to carry out the same operation a number of times
2
Q
recurtion has three essential characteristics
A
- a stopping contition/base case must be included which wehn met means that the routine will not call itself and start ‘unwinding’
- for inpur values other than the base case, the routine must call itself
- the base case must be reached after a finite number of calls
3
Q
stopping conditions
A
required or the routine never “unwinds”
Avoids endless recursion
4
Q
recursion code example
A
def factorial(n): if n ==1: return 1 else: return n*factorial (n-1)