4. DP summary #
Created Thursday 12 March 2020
With a basic observation of what was happening vs what should happen, we can do wonders. Dynamic Programming is really very clever and easy programming.
- Make a bruteforce recursive solution.
- Make a memoized.
Steps to follow:
- Make an array.
- Initialize it if required, i.e for visited or unvisited mostly.
- Enter the concrete values into the array
- Decide the relationship between the answers and the question.
- What is the dependency.
- Is it counting or optimum. Here we check for the min or just add in case of counting.
- Are there multiple ways to reach the same answer, does it give the wrong thing, duplicacy etc. Partly covered in counting vs optimum.
- Can values be skipped, this will drastically reduce the array size.
- Write it iteratively.
- Most solutions give O(n) both space and time. Time is O(kn) in most case for some case/constraint dependent n;