Recursions Flashcards
1
Q
What is a recursive function?
A
It is a way of programming where a subroutine is defined in terms of itself which enables it to be able to call on itself one or more times in its body and terminates when its stopping condition is reached.
2
Q
What are the advantages of recursion?
A
- A complex task can be broken down into simpler independent sub-problems using recursion
- Recursive functions make the code look clean and elegant
- Sequence generation is easier with recursion than using some nested iteration
3
Q
What are the disadvantages of recursion?
A
- Risk of infinite recursion when a programmer misses out a base case
- Sometimes, the logic behind the recursion can be hard to follow
- Recursive functions are hard to debug
- Recursive routines can take up a lot of memory and time in execution owing to the overheads involved in repeatedly calling the subroutine and storing and retrieving return addresses and parameters