Recursion and Dynamic Programming Flashcards
Hints of recursion
It can be built off of sub problems. Look for these problem statements “Design an algorithm to compute the nth…”, “Write code to list the first n…”, “Implement a method to compute all…”
Bottom-Up Approach
We start with knowing how to solve the problem for a simple case. Then we figure out how to solve the problem for two elements, then for three elements, and so on. Think about how you can build the solution for one case off of the previous case.
Top-Down Approach
Think about how we can divide the problem for case N into sub problems. Be careful of overlap between the cases.
Half-and-half approach
Divide the data set in half. Think of binary search and merge sort.
Recursive vs. Iterative Solutions
All recursive solutions can be implemented with an interactive solution. Recursive algorithms require at least O(n) space complexity where n is the depth of its recursion tree.
Dynamic Programming
Taking recursive problems and finding the overlapping sub problems (that is, the repeated calls). You then cache those results for future recursive calls. Alternatively, you can study the pattern of the recursive calls and implement something iterative. You still cache previous work. Typically used to refer to bottom-up work, but can also refer to top-down work.
Memorization
Like dynamic program, it aims to cache repeated calls in a recursive problem. However, it is specific to top-down approach.