DecodingIntuition
DecodingIntuition
  • 2
  • 214 155
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.
มุมมอง: 17 587

วีดีโอ

Dynamic Programming isn't too hard. You just don't know what it is.
มุมมอง 197K3 หลายเดือนก่อน
#dynamicprogramming #leetcode

ความคิดเห็น

  • @MadDeuceJuice
    @MadDeuceJuice 20 ชั่วโมงที่ผ่านมา

    The dirties, most filthy approach in all of programming…

  • @neoanderson1865
    @neoanderson1865 วันที่ผ่านมา

    this video confused me even more. i hope one day it makes sense to me

  • @anmax
    @anmax วันที่ผ่านมา

    Dude, you changed my programming life

  • @bokistotel
    @bokistotel วันที่ผ่านมา

    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.!!

  • @riya-qz9uk
    @riya-qz9uk 3 วันที่ผ่านมา

    why is cached complexity O(n) for catalan?

  • @ohmpatel3286
    @ohmpatel3286 6 วันที่ผ่านมา

    best explanation of DP i've ever seen, love the idea of not relying on tables

  • @gr.4380
    @gr.4380 8 วันที่ผ่านมา

    Please return this is the best series on programming problem solving I've seen 😢

  • @user-ee1fn4vt8b
    @user-ee1fn4vt8b 9 วันที่ผ่านมา

    witchcraft

  • @riddhivekariya9086
    @riddhivekariya9086 14 วันที่ผ่านมา

    We'd worship you , if you keep uploading man

  • @riddhivekariya9086
    @riddhivekariya9086 14 วันที่ผ่านมา

    Keep uploading please

  • @avid4839
    @avid4839 14 วันที่ผ่านมา

    Wish you finished the thought you had at 15:52. What were you going to do to fix your naive recursion?

  • @WilliamWang-m4i
    @WilliamWang-m4i 17 วันที่ผ่านมา

    You are DP GOD🙏 It's all math down the root. So clear. I'll rewatch this multiple times. THIS is TRUE problem solving.

  • @_derpyvik_8273
    @_derpyvik_8273 18 วันที่ผ่านมา

    Commenting for the algorithm, thanks man

  • @WilliamWang-m4i
    @WilliamWang-m4i 19 วันที่ผ่านมา

    I see wisdom and clarity. Thank you.

  • @mxpph
    @mxpph 20 วันที่ผ่านมา

    this is the greatest educational video ive ever seen on this entire platform

  • @heinrichpreussen
    @heinrichpreussen 23 วันที่ผ่านมา

    holy fuck this video is awesome

  • @bigboland6160
    @bigboland6160 23 วันที่ผ่านมา

    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

  • @dIancaster
    @dIancaster 24 วันที่ผ่านมา

    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.

  • @pedro_soares_bhz
    @pedro_soares_bhz 25 วันที่ผ่านมา

    Damn, that is beautiful reasoning right there!

  • @psibarpsi
    @psibarpsi 25 วันที่ผ่านมา

    the right image is related to tabulation. what's the left image related to?

  • @lucascamelo3079
    @lucascamelo3079 27 วันที่ผ่านมา

    Repeat with me: recursion can't be faster than procedural

  • @sgalloway111
    @sgalloway111 28 วันที่ผ่านมา

    Thank you

  • @rubyciide5542
    @rubyciide5542 28 วันที่ผ่านมา

    I hate cache and that's all the reason i need to skip learning dp

  • @nolan_meyer
    @nolan_meyer 29 วันที่ผ่านมา

    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

  • @ru2979
    @ru2979 หลายเดือนก่อน

    Bro are u a GM on CF or wot , u explaining concepts like that 😮 reminds me of my DSA trainer online 😮😮😢

  • @Harishiv18
    @Harishiv18 หลายเดือนก่อน

    0:33 can’t believe we are still taking shots at the verse pc build guide

  • @andrewsoares8941
    @andrewsoares8941 หลายเดือนก่อน

    You are fucking amazing guy, wtf. Thanks a lot

  • @rcj1337
    @rcj1337 หลายเดือนก่อน

    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

    • @dev__noob_9299
      @dev__noob_9299 24 วันที่ผ่านมา

      I see what you did there ... 🧐

  • @mingoc1785
    @mingoc1785 หลายเดือนก่อน

    Is your problem solving adapted from how to solve it? That book’s is next in my reading list

  • @amazingbanter
    @amazingbanter หลายเดือนก่อน

    The side effects tidbit was probably the most important part for me. The subproblems must be pure.

  • @isaacalinda
    @isaacalinda หลายเดือนก่อน

    “HAANNKKK DONT ABBREVIATE DYMAMIC PROGRAMMING ON THE THUMBNAIL”

  • @davidpark2116
    @davidpark2116 หลายเดือนก่อน

    great explanation! this made things so clear. how do you get those vim motions in leetcode?

  • @Darth_Insidious
    @Darth_Insidious หลายเดือนก่อน

    At it's basic essence, dynamic programming is looking for ways to reuse computational steps for multiple steps/iterations of a problem.

  • @tagberli
    @tagberli หลายเดือนก่อน

    Best explanation on the entire planet, the world needs you, man

  • @OJ000
    @OJ000 หลายเดือนก่อน

    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

    • @DecodingIntuition
      @DecodingIntuition หลายเดือนก่อน

      You might want to check again. @cache is used.

  • @nickolasbrown2260
    @nickolasbrown2260 หลายเดือนก่อน

    I agree . Dp is just misunderstood. 😂

  • @therealg4197
    @therealg4197 หลายเดือนก่อน

    Now do one for greedy problems

  • @PragMero
    @PragMero หลายเดือนก่อน

    Display Port

  • @adamrushford
    @adamrushford หลายเดือนก่อน

    This shit is epic, never stop please

  • @joemoonwhitehead
    @joemoonwhitehead หลายเดือนก่อน

    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.

  • @michaelantoun9353
    @michaelantoun9353 หลายเดือนก่อน

    how many spins did it take to land on seg tree?

    • @DecodingIntuition
      @DecodingIntuition หลายเดือนก่อน

      Not even joking, it was literally the first one.

  • @NephiLynn
    @NephiLynn หลายเดือนก่อน

    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

  • @MorningNapalm
    @MorningNapalm หลายเดือนก่อน

    Why do you say "what even is dynamic programming"? English would be "what is dynamic programming even".

    • @DecodingIntuition
      @DecodingIntuition หลายเดือนก่อน

      "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!

    • @MorningNapalm
      @MorningNapalm หลายเดือนก่อน

      @@DecodingIntuition I am British :D Putting even up front is a very recent thing, and mostly happens in America.

  • @JohnDoe-sq5nv
    @JohnDoe-sq5nv หลายเดือนก่อน

    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.

  • @BananaButcher
    @BananaButcher หลายเดือนก่อน

    Smoothhh

  • @elarsilmarin
    @elarsilmarin หลายเดือนก่อน

    order doesn't matter w combinations inherently. when order matter it's called permutations, right?

  • @morenofranco712
    @morenofranco712 หลายเดือนก่อน

    I'm getting drunk for you tonight

  • @alluysl
    @alluysl หลายเดือนก่อน

    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)

    • @alluysl
      @alluysl หลายเดือนก่อน

      Woe is me, the difference between the two runs was 1ms more than I said

  • @waklord1830
    @waklord1830 หลายเดือนก่อน

    i actually slept during this video and this guy jump scared me

  • @zFake
    @zFake หลายเดือนก่อน

    this is your first video? dude this is good