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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

recurtion has three essential characteristics

A
  1. a stopping contition/base case must be included which wehn met means that the routine will not call itself and start ‘unwinding’
  2. for inpur values other than the base case, the routine must call itself
  3. the base case must be reached after a finite number of calls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

stopping conditions

A

required or the routine never “unwinds”
Avoids endless recursion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

recursion code example

A
def factorial(n):
       if n ==1:
            return 1
        else:
            return n*factorial (n-1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly