Recursion - Standard Flashcards
Linear recursion
amount of information stored is dependend linearly on n (size) - creates a chain of defered operations
Tree/branching recursion
Like fibonnaci
for very large values of n, large recursive stacks are stored in memory making this type of recursion slow and memory inefficient
Tail recursion
recursive call is the last thing that is done before returning
- last call evaluates function’s value
nothing from the higher call eed to be stored
optimised for memory use
tail recursive factiorial
facAux 0 r = r
facAu n r = facAux (n-1)(r*n)
facTail n = facAux n 1
tail recursive fibonnaci (remember that is Tree recursive)
fibAux n r e s u l t previous
| n == 0 = r e s u l t
| otherwise = fibAux (n − 1) ( r e s u l t + previous ) r e s u l t
f i b T a i l n
| n == 0 = 0
| otherwise = fibAux n 1 0