- 2
- 214 155
DecodingIntuition
เข้าร่วมเมื่อ 16 ก.ค. 2024
Explaining the algorithms for writing algorithms
Dynamic Programming: 3 consistent steps from recursive to iterative
If you can do it recursively, you can do it iteratively. I'll show you 3 steps to convert any recursive dynamic programming solution into an iterative one: defining bounds, managing dependencies, and replacing recursive calls with values!
If you haven't watched my first video on dynamic programming, go watch that first: th-cam.com/video/gK8KmTDtX8E/w-d-xo.html.
If you haven't watched my first video on dynamic programming, go watch that first: th-cam.com/video/gK8KmTDtX8E/w-d-xo.html.
มุมมอง: 17 587
วีดีโอ
Dynamic Programming isn't too hard. You just don't know what it is.
มุมมอง 197K3 หลายเดือนก่อน
#dynamicprogramming #leetcode
The dirties, most filthy approach in all of programming…
this video confused me even more. i hope one day it makes sense to me
Dude, you changed my programming life
Using your AMAZING approach i converted this problem to a backracking problem to find all paths: def counting_change_paths(amount, coins): def whatAreDistinctWaysStartingWith_toMake_(i,n,coins): if n == 0: result.append(combination[:]) return if i == len(coins): return smaller_amount = n - coins[i] if smaller_amount >= 0: combination.append(coins[i]) whatAreDistinctWaysStartingWith_toMake_(i,smaller_amount,coins) combination.pop() whatAreDistinctWaysStartingWith_toMake_(i+1,n,coins) result = [] combination = [] whatAreDistinctWaysStartingWith_toMake_(0,amount,coins) return result print(counting_change_paths(4, [1,2,3])) -> [[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2]] BTW: This golden nugget of logic feels like a breakthrough - it's as if I've learned a completely new way of thinking. Instead of blindly memorizing or visualizing inconsistent decision trees, I finally see a logical anchor to build my understanding. I want to add that I've often struggled to ground my reasoning and instead relied on rote learning, but this feels like a real step forward.!!
why is cached complexity O(n) for catalan?
best explanation of DP i've ever seen, love the idea of not relying on tables
Please return this is the best series on programming problem solving I've seen 😢
witchcraft
We'd worship you , if you keep uploading man
Keep uploading please
Wish you finished the thought you had at 15:52. What were you going to do to fix your naive recursion?
You are DP GOD🙏 It's all math down the root. So clear. I'll rewatch this multiple times. THIS is TRUE problem solving.
Commenting for the algorithm, thanks man
I see wisdom and clarity. Thank you.
this is the greatest educational video ive ever seen on this entire platform
holy fuck this video is awesome
honestly completely ignoring what this video is about and the dynamic programming part, you should make a shorter video just going over how you analyze and write out the different parts to figure out exactly what your trying to solve. ima start doing this for every leetcode problem, and honestly any recruiter would probably be shocked and impressed if you did all this during an interview
You are a goddamn machine. I'm in awe. The way you knew it would pass even before running it? I'm so deeply impressed.
Damn, that is beautiful reasoning right there!
the right image is related to tabulation. what's the left image related to?
Repeat with me: recursion can't be faster than procedural
Thank you
I hate cache and that's all the reason i need to skip learning dp
20:17 re: Richard Bellman “I spent the Fall quarter (of 1950) at RAND. My first task was to find a name for multistage decision processes. “An interesting question is, ‘Where did the name, dynamic programming, come from?’ The 1950s were not good years for mathematical research. We had a very inter- esting gentleman in Washington named Wilson. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word, research. I’m not using the term lightly; I’m using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term, research, in his presence. You can imagine how he felt, then, about the term, mathematical. The RAND Cor- poration was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Cor- poration. What title, what name, could I choose? In the first place I was interested in planning, in decision making, in thinking. But planning, is not a good word for various rea- sons. I decided therefore to use the word, ‘programming.’ I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying-I thought, let’s kill two birds with one stone. Let’s take a word that has an absolutely precise meaning, namely dynamic, in the clas- sical physical sense. It also has a very interesting property as an adjective, and that is it’s impossible to use the word, dynamic, in a pejorative sense. Try thinking of some com- bination that will possibly give it a pejorative meaning. It’s impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activi- ties” www.researchgate.net/publication/220243993_Richard_Bellman_on_the_Birth_of_Dynamic_Programming
Bro are u a GM on CF or wot , u explaining concepts like that 😮 reminds me of my DSA trainer online 😮😮😢
0:33 can’t believe we are still taking shots at the verse pc build guide
You are fucking amazing guy, wtf. Thanks a lot
2:27 ”different view of not only DP, but also problem solving - as a hole” - I get it now, DP and holes go toghether, makes sense
I see what you did there ... 🧐
Is your problem solving adapted from how to solve it? That book’s is next in my reading list
The side effects tidbit was probably the most important part for me. The subproblems must be pure.
“HAANNKKK DONT ABBREVIATE DYMAMIC PROGRAMMING ON THE THUMBNAIL”
great explanation! this made things so clear. how do you get those vim motions in leetcode?
At it's basic essence, dynamic programming is looking for ways to reuse computational steps for multiple steps/iterations of a problem.
Best explanation on the entire planet, the world needs you, man
This video definitely taught me a lot, but I think you may be wrong in the time analysis for the code you wrote. It doesn't look like your caching the values for each state anywhere so the recursion is still doing many recomputations. Due to this I'd say your code has exponential growth rather than polynomial growth. I tested this out by putting your same code into leet code and got a TLE. I then added a 2d array to act as a cache and was able to submit successfully
You might want to check again. @cache is used.
I agree . Dp is just misunderstood. 😂
Now do one for greedy problems
Display Port
This shit is epic, never stop please
Funny as fuck. Insightful as hell. If my maths teacher was as enthusiastic as you I'd likely have learned what inductive thinking actually was.
how many spins did it take to land on seg tree?
Not even joking, it was literally the first one.
this is not the kind of DP i see daily and i think its funny ive already seen 4 different meanings for DP in 4 different subjects when i saw DP in my timeline i thought this was ab to be a fighting game video lmao
Why do you say "what even is dynamic programming"? English would be "what is dynamic programming even".
"What even is..." is a common English phrase using "even" as an adverb. Your usage doesn't make sense because you end the sentence with "even" which modifies nothing. Hope that helps!
@@DecodingIntuition I am British :D Putting even up front is a very recent thing, and mostly happens in America.
I've found success in explaining recurrence relations as states and state relations. Becuase that is what they are, just not a way that many think about them as. This is also the way I write recursive functions and how I explain to others how to write them: Think state and state transitions, then think stopping point. Then, if needed, think about how store values in states directly, and think about ordering of the operations to calculate the right states first in order to avoid storing too much data you don't need, if that indeed is an issue.
Smoothhh
order doesn't matter w combinations inherently. when order matter it's called permutations, right?
I'm getting drunk for you tonight
19:06 the funny last minute switch from (probably) a simple calloc and an assignment to a list concatenation trading a line of code for 6ms (± noise)
Woe is me, the difference between the two runs was 1ms more than I said
i actually slept during this video and this guy jump scared me
this is your first video? dude this is good