recursion Flashcards

1
Q

state definition of recursion [1m]

A

procedure that calls itself and returns a predetermined value when base case is encountered

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

3 conditions of recursive functions

A
  • it should have at least one base case that returns a value directly without calling itself
  • calls itself when base case is unmet
  • each successive recursive call should reduce the input to bring it closer to the base case
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

advantage of recursion

A

can be split among multiple processors (when func calls itself twice in one line, calc happen for both func calls simultaneously)

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

disadvantage of recursive

A

greater overhead due to the need to push and pop function frames on and off the call stack (more time consumption in program execution)

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

the call stack

A
  • stack is a data structure that follows LIFO order
  • the function frame contains all the variables in that instance of the recursive function
    when function is called:
  • function frame is allocated for the function call and pushed onto the call stack
    when func call terminates:
  • function frame is popped off the call stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

difference btwn trace table & trace diagram? (visual)

A

hope u do! jiayou!
(check recursion notes if u dont)

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