CHAPTER: RECURSION Flashcards

1
Q

Recursion

A
  • when procedure or function calls itself
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Essential features of Recursion

A
  • must have base case
  • must have general case
  • must unwind once base case is reached
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why STACK appropriate for Recursion

A
  • Last in first out
  • each recursive call can push to stack and then popped as function ends
  • enables unwinding to maintain required order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Advantages of recursion

A
  • produce simpler, more natural solutions to a problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Disadvs of recursion

A
  • less efficient computer time, in storage space as lots used for states and return addresses
  • could lead to inifinte recursion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How computer translates recursive program code

A

before procedure call is execute, current state register stored onto stack
- when returning register reinstate one stack
- when bases case maet, algorithm unwinds
- the last set of values taken off the stack in reverse orderU

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

Unwinding

A
  • when base is reached all data stored in stack gets popped out from the top of the stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly