2.2.1 programming techniques Flashcards

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

what is recursion?

A

a function that calls on itself
it has a terminating/base case
it also has a general case

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

how do you convert a recursive algorithm to an iterative algorithm?

A
  • the opposite of the base case is used for the while loop condition
  • the parameters in the recursive calls of the function are set as changing the variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what are the advantages of recursive algorithms?

A
  • uses less lines of code
  • well suited to certain problems/elegant solution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are some disadvantages of recursive algorithms?

A
  • risk of stack overflow
  • uses more memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how can you trace through a recursive algorithm?

A
  1. use a table (if provided) and write each function call, the value of the parameters and the return
  2. write each line of code and write the decisions (true/false) next to it. Then do this for the next call of the function with the correct values. finally, write the return values of each instance of the function call
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some examples of recursive algorithms?

A
  • merge sort
  • binary tree search
  • calculating factorials
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly