Recursion Flashcards
Benefits of using recursion instead of iteration 1
More natural to read (1)
Quicker to write / less lines of code. (1)
As some functions are naturally
recursive (1)
Drawbacks of using recursion instead of iteration 1
Can run out of stack space / memory
(1) (due to too many calls (1)) causing
it to crash (1) This can be avoided with
tail recursion (1)
Difference between recursion and iteration memery
Recursion uses more memoery
Difference with variables
Recursion declares new variables and are put onto stack each time whereas iteration re uses same variables
Difference with running out of memory
Recursion can run out of memory/stack space while iteration cannot run out memory
Difference with referential
Recursion will call itself whereas iteration wull not
Benefits of recursion to iteration 2
Suited to certain problems (1) For
example those using trees (1)
Can reduce the size of a problem with
each call. (1)
Drawbacks of recursion to iteration 2
More difficult to trace / follow (1) as
each frame on the stack has its own
set of variables (1)
Requires more memory than the
equivalent iterative algorithm.
Usually slower than iterative methods
(1) due to maintainence of the stack