CHAPTER: RECURSION Flashcards
1
Q
Recursion
A
- when procedure or function calls itself
2
Q
Essential features of Recursion
A
- must have base case
- must have general case
- must unwind once base case is reached
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
4
Q
Advantages of recursion
A
- produce simpler, more natural solutions to a problem
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
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
7
Q
Unwinding
A
- when base is reached all data stored in stack gets popped out from the top of the stack