I have been doing this with success 1. Identify states & understand state changes 2. Identify base case(s) 3. Identify recurrence relation 4. Top-down recursion + memoization 5. Bottom-up Tabulation 6. If possible, optimize space by removing a dimension in state
4th step sometimes not possible, but yeah up to 3 definitely.
very good summary of the step by step optimisation of DP problems, but it is hard for new learner to understand these 4 steps without a full blown explanation.
You could solve it in O(log(n)). Some say this problem could be solved in O(1), but they need to calculate the square root, and this costs O(log(n)).
I'm just a tradesman and stumbled upon this vid. I have NO idea what's going on but it looks cool
I find that top-down solutions are easier to understand due to the decision tree nature of the solution as opposed to the bottom-up with dp that is sometimes harder to find the transition step.
Great video demonstrating progressive code refinement. Still not sure if the first step should be called "recursive backtracking". As discussed in previous video, think this is just "naïve recursion".
What do DP do?: It actually selects one best solution from all the possibilities And the possibilities are reduced by reusing/Memorization/Tabulation,(when there are 2 or more subproblems overlapping then we can avoid those subproblems and substitute from the memorization 😎)
What's complicated about DP IMO is figuring out what do the output depend on in such a way that it's memoizable, when facing new and complicated problems, It's not obvious at all
Great tips! What would your tips for nailing down a ZYLYTY code challenge?
With these shorts, i should be able to become a code guru in one hour.
How to do the 4th step in antoher algorithm? For example the knapsack?
Hey Gregg, I'd love to see a deep dive into DP. Most importantly, I'd like to know how I can convert my naive approach progress from top-down to bottom-up to true dp solutions. Thanks in advance.
I’ve seen most jobs wanting the degree in computer science, did you learn on your own or did you get your degree? I’m asking because I’m interesting in learning this skill!
Nice breakdown! I've always found DP problems a bit tricky, but these steps make it sound way more manageable. Recursion to bottom-up with no memory is like leveling up each time! For those battling the usual coding interview prep grind, maybe mix it up with some real-world problems on zylyty too. They focus more on practical stuff which might save us from endless leetcode academic loops and you get to show off actual skills companies care about. Less AI cheating, more legit coding cred!
yeah, thanks that makes a lot of sense, but is there a book that i can read to master these 3 types of dp solutions?
I think the memo dict would be a new one for each stack frame. I might be wrong. You are better off using lru_cache from functools or make the dict global
Hi! I am a beginner in DSA and can only do easy array and string questions. How to start learning DP and Graph? And from where to learn? Like I need a playlist that explains theory(so i can make notes) + codes If anyone is able to provide any links, much thanks😊
Hey there Justin. How did you fix the ears? Looking really nice
@GregHogg