Recursion & Dynamic Programming Flashcards

1
Q

Bottom-Up Approach

A

The bottom-up approach is often the most intuitive. We start with knowing how to solve the problem for a simple case, like a list with only one element. Then we figure out how to solve the problem for two elements, then for three elements, and so on. The key here is to think about how you can build the solution for one case off of the previous case (or multiple previous cases).

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

Top-Down Approach

A

The top-down approach can be more complex since it’s less concrete. But sometimes, it’s the best way to think about the problem.
In these problems, we think about how we can divide the problem for case N into subproblems.

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

Half-and-Half Approach

A

In addition to top-down and bottom-up approaches, it’s often effective to divide the data set in half.
For example, binary search works with a “ha!f-and-half”approach. When we look for an element in a sorted array, we first figure out which half of the array contains the value. Then we recurse and search for it in that half.
Merge sort is also a “half-and-half” approach. We sort each half of the array and then merge together the sorted halves.

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