YEAR 2 CO2 WEEK 4 RECURSION Flashcards

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

Define Recursion.

A

Where a function or sub-routine calls itself as part of the overall process.

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

What needs to be included in recursion to ensure it doesn’t run forever?

A

Some kind of limit is built into the function so recursion ends when a certain condition is met.

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

How is a execution stack used with recursion?

A

An execution context forms when function is called.
This places itself on the execution stack.

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

How does Recursion get a return value?

A

We are waiting for return values coming from other execution contexts.
These contexts are higher up in the stack.
When last item on stack finished executing, the context generates a return value.
Gets passed down as a return value for each recursive case to the next item.
The execution context then popped off the stack.

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

What is the difference between head Recursion and tail Recursion?

A

With head Recursion the recursive call is not the last thing done by the function. After returning back still something left to do.

With tail recursion the last statement in the function calls itself.

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

What are the benefits of recursion?

A

More natural to read.
Quicker to write/less lines of code
Can reduce size of problem with each call.

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

What are the drawbacks to recursion?

A

Faulty recursion will never end and quickly end with a stack overflow.
Makes heavy use of the stack.
Usually slower.

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