Recursion Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Benefits of using recursion instead of iteration 1

A

More natural to read (1)
Quicker to write / less lines of code. (1)
As some functions are naturally
recursive (1)

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

Drawbacks of using recursion instead of iteration 1

A

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)

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

Difference between recursion and iteration memery

A

Recursion uses more memoery

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

Difference with variables

A

Recursion declares new variables and are put onto stack each time whereas iteration re uses same variables

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

Difference with running out of memory

A

Recursion can run out of memory/stack space while iteration cannot run out memory

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

Difference with referential

A

Recursion will call itself whereas iteration wull not

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

Benefits of recursion to iteration 2

A

Suited to certain problems (1) For
example those using trees (1)
Can reduce the size of a problem with
each call. (1)

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

Drawbacks of recursion to iteration 2

A

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

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