unit 5 - recursion Flashcards

1
Q

recursion

A

when a function calls itself

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

recursion is useful when

A

something calls for a repeated process with different values / close values, but only returning one value

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

iterative > recursion for

A

speed and memory

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

Recursive > iterative for

A

keeping track of previous steps

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

branching path problems

A

different conditions require different procedures;
recursion is useful for finding the optimal path

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

Abstract data type best representing recursive function calls

A

stack

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

greedy algorithm

A

takes the step that brings it closest to its goal at every junction

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

coin counting: greedy algorithm

A

sort coin values;
for each value, while it is less than the amount of money needed, subtract that value from the amount;
append # of coins for each subtraction operation

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

downside to greedy algorithms

A

the biggest step is not always the most efficient;
with arbitrary coins, a coin counting algorithm may not take the most efficient steps. Less coins will be received with a different coin

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

coin counting: recursive algorithm

A

if amt in coins: return 1;
validcoins = [c in coins if c < amt];
for coin in valuelist: numcoins = 1 + fewest_coins(amt - coin, coins);
If numcoins < mincoins: mincoins = numcoins

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

memoization

A

the practice of storing a subset of solved problems

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