recursion Flashcards

1
Q

recursive functions often use more system resources than their iterative counterparts

A

true

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

recursion might make the program “easier” for other programmers to read at the cost of system resources (e.g. stack usage)

A

true

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

following a list of non-repeating /known instructions (driving directions) is best suited to …

A

use iteration to go through a list of instructions

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

trying to find a store in a city (unknown directions, need to look at all possibilities)… is best suited to…

A

use recursion for maze-solving/ backtracking type searches. Break into smaller problems (does this street contain the store?) and either recurse or backtrack from there

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

binary search keeps track of lower bound, upper bound, middle value: if middle value is higher than search value…

A

means search item is in lower half of array
1. discard upper half of array
2. (middle index + 1) becomes upper bound
3. lower index stays same
redo recursive search with middle index = (UB-LB)/2

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

binary search keeps track of lower bound, upper bound, middle value: if middle value is lower than search value…

A

means search item is in upper half of array
1. discard lower half of array
2. (middle index -1) becomes lower bound
3. upper index stays same
redo recursive search with middle index = (UB-LB)/2

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

what is a magic index

A

an index of a list that has the same value as the index m[i]=i

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