10. Dynamic Programming: Advanced DP

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 61

  • @vishnusingh4118
    @vishnusingh4118 5 лет назад +68

    5:13 Longest Common Palindromic Sequence ( problem 1)
    21:55 Second problem (optimal Search Trees) starts
    54:14 Alternating Coins Game (3rd and last example)

    • @Skovorodnikof
      @Skovorodnikof 5 лет назад

      you saved my energy :D

    • @robertalaverdyan3150
      @robertalaverdyan3150 4 года назад +2

      Thanks man. Saved me time which I spent on writing this comment lol

    • @vishnusingh4118
      @vishnusingh4118 4 года назад

      @@robertalaverdyan3150 Haha. It took you THAT LONG to write this comment !? :p ...Just kiddin! Glad it could be of use to you.

  • @tutotechie9043
    @tutotechie9043 3 года назад +20

    All of Prof. Devadas lectures are just amazing. In particular, this is probably the best video I watched about DP.

  • @Hallo.Q
    @Hallo.Q 3 года назад +10

    One of the best DP lectures I have ever seen. Thanks to MIT open course ware and Prof. Srinivas Devadas

  • @brysongalapon877
    @brysongalapon877 8 лет назад +17

    A counter-example to the greedy optimal BST algorithm using 3 nodes has w1 = 10, w2 = 11, w3 = 12. Cheers!

  • @stormanning1163
    @stormanning1163 7 лет назад +17

    Srinivas and Erik you guys are the real Gs!

  • @RuiLopesFR
    @RuiLopesFR 6 лет назад +9

    If you really want a counter example for 3 nodes, I suggest 1(w=20), 2(w=19), 3(w=18)
    Greedy would unbalance the tree in 1->2->3 giving a cost of 112
    Optimal solution would give a balanced tree of 13 that would cost 95

    • @davidloter5391
      @davidloter5391 3 года назад +2

      Although I have absolutely no idea what you are talking about, I have to concur.

    • @guidomartinez5099
      @guidomartinez5099 2 года назад

      Good example. Also note that if you just choose individual weights to be N+1, N+2,..., N+n, you get a completely unbalanced tree (similar to a linked list). But if N is high enough, those differences should be negligible, so a balanced BST would be best.

  • @anshprakash1778
    @anshprakash1778 6 лет назад +9

    It was a very good lecture, everything simplified and quite interactive class.Thanks

  • @Garentei
    @Garentei 4 года назад +2

    dp[i, j] = min(dp[i, j], e(i, r-1) + e(r+1, j) + wr * (depth+1)) also works if you add the depth every time you go down the recursion tree.

    • @Garentei
      @Garentei 4 года назад

      @@useForwardMax You are completely right. In fact, I did not have r in the dp when I tested it, it just slipped when I made this comment, haha.

  • @prachikhobragade4631
    @prachikhobragade4631 5 лет назад +41

    I can see Eric Demaine sitting in the first row at (16:16) , he might be wondering, no subproblems and guessing, just directly the recurrence relation :D

  • @mattg9601
    @mattg9601 2 года назад +1

    "If you go first your guaranteed to not lose". Man goes second and still won.

  • @albertoferrada2075
    @albertoferrada2075 Год назад

    In the last example I don't really understand why should we assume that the second player chooses the min of his options at the moment. Isn't they running a greedy?, it is said that they play optimally, so why don't we model them decision as another dp?

  • @adityasahu96
    @adityasahu96 6 лет назад +1

    why we need to add all of the node (51:40) i though we need add wr (i

    • @yesil1026
      @yesil1026 5 лет назад +2

      It is very subtle, indeed. As the instructor said, for e(i,j) you add wi to wj once. For the next depth, when you compute e(i, r -1) you again add wi to w(r-1) so in total you add wi to w(r-1) twice, which corresponds to the increasing depth. The same thing goes for e(r+1, j). you add w(r+1) to wj once again for this calculation and in total w(r+1) to wj is added twice. But wr is added only once since it remained in the upper level (depth) and not included both e(i, r-1) and e(r+1, j)

    • @kongzilla2897
      @kongzilla2897 3 года назад

      @@yesil1026 Woww!! That's a nice explanation Thanks :)

  • @xiaomengli8681
    @xiaomengli8681 5 лет назад +3

    The third question should be MinMax problem.

  • @nanto88
    @nanto88 6 лет назад +6

    Erik Demaine 16:17

  • @islams_beauty-c8c
    @islams_beauty-c8c 8 месяцев назад

    what is wi's and pi's I didn't understand it yet.

  • @ariellubonja7856
    @ariellubonja7856 3 года назад

    First example question: the pseudocode shown at 22:33 only works with contiguous palindromes, am I wrong?
    Whereas the brain teasers at the start weren’t necessarily contiguous e.g. “rotator” out of “turboventilator”
    I do not see how the code can ever figure out “rotator” if you start it with L(0,end)
    Also I don’t see why nr. Of subproblems is n squared

    • @digama0
      @digama0 2 года назад

      The code as written only calculates the length of the best (noncontiguous) palindrome, but it will in fact give L(0, 14) = 7:
      L(turboventilator) = max(L(urboventilator), L(turboventilato))

    • @SMA265
      @SMA265 2 года назад

      @@digama0 👍🏻

  • @EliotMcLellan
    @EliotMcLellan 6 лет назад +10

    Greedy al gore rhythm sounds like my kind of thing! I use greedy algorithms at my home in my own programs all the time

  • @cembirler
    @cembirler 6 лет назад

    Why there were only 5 trees for n=3? (Why did he look at the different structures only, but not different ways to form the multiplication?)

    • @FeroChau
      @FeroChau 6 лет назад +3

      Because it is binary search tree.

  • @kongzilla2897
    @kongzilla2897 3 года назад

    Thank You sir !! :)

  • @shreyasingh1258
    @shreyasingh1258 4 года назад

    can anyone help me with the complexity of coin game ques how is no of sub problems n square?

    • @junzhai1715
      @junzhai1715 3 года назад

      the number of pairs of (i,j) where i

  • @axdx8085
    @axdx8085 8 лет назад

    Why do we need to minimize opponents move. If we just consider all possible move opponent can play and just maximize shouldn't we still get the correct answer? Unless we specifically demand the opponent to optimize as well.

    • @vishnukl
      @vishnukl 8 лет назад +3

      we are actually asking the opponent to play his best move by minimizing our optimal gain.

    • @antontitov2
      @antontitov2 7 лет назад

      Maybe an easier (to understand) solution is that given V(i, j) you pick i or j and pass the move to the opponent. Whatever is he's best, you get the rest. So V(i, j)=max(v[i]+sum(i+1, j)-V(i+1, j), v[j]+sum(i, j-1)-V(i, j-1)). The sum(i, j) is O(1) given O(n) precomputation.

    • @AnNguyen-fw1mt
      @AnNguyen-fw1mt 6 лет назад

      I'm guessing since it's zero sum, maximizing our score and minimizing theirs would give identical solution.

    • @adamrichter8792
      @adamrichter8792 4 года назад

      @@antontitov2 I am not sure what you mean by sum(i,j) here. It looks to me as if the point that your and Praveen's point can be made more clearly by omitting the references to sum, like so (using C "?" syntax): V(i,j) = (i == j) ? v[i] : max(v[i]-V(i+1,j), v[j]-V(i,j-1)).

    • @tarunpahuja3443
      @tarunpahuja3443 2 года назад

      Actually we are computing the max value that we can certainly win with even if opponent play optimally.

  • @hikaru-hokkyokusei
    @hikaru-hokkyokusei 4 года назад

    So i don't get it... why would a teacher be sitting in student's benches when another theacher is teaching...? :X

    • @lMaqz
      @lMaqz 3 года назад +1

      To learn, always time to learn

  • @jonathanmoralesstrength6993
    @jonathanmoralesstrength6993 8 лет назад

    so do Srinivas Devadas and Eric Demain both teach for the same class? Or are these 2 different classes? Also, is this masters material?

    • @mitocw
      @mitocw  8 лет назад +7

      +Jonathan Morales Strength There are three instructors for this undergraduate course: Prof. Erik Demaine, Prof. Srinivas Devadas, Prof. Nancy Lynch. See the course on MIT OpenCourseWare for more information at ocw.mit.edu/6-046JS15

    • @MarsCheng
      @MarsCheng 7 лет назад +1

      This is an undergraduate-level course. They taught it together.

    • @KundanSingh-iz8jw
      @KundanSingh-iz8jw 5 лет назад

      B.p

    • @KundanSingh-iz8jw
      @KundanSingh-iz8jw 5 лет назад

      .

  • @SphereofTime
    @SphereofTime Месяц назад

    1:04:04 dp mazimize

  • @loam
    @loam 4 года назад +1

    One thing I don't get about all those recursions is, why are you guys don't mention that stack is limited and able to hold limited recursive calls to functions, and for some big enough input number for problem to be solved for, you might get stack overflow.
    Or is this all just theory and one shouldn't be thinking about how to use it in practice?

    • @proximush
      @proximush 4 года назад +1

      Virtually every DP problem using recursion + memoization (i.e. top-down approach) can be implemented in an iterative way starting from the base cases and building up (i.e. bottom-up approach). Concretely, if the subproblems depend, say, on two parameters i,j in some range, then you iteratively fill a 2-dimensional matrix which at the entry (i,j) stores the value of subproblem i,j.

    • @digama0
      @digama0 2 года назад

      Also, if an algorithm requires a deep stack you can always heap-allocate it by using an explicit stack data structure so that you won't overflow unless you actually run out of physical memory. Usually, even "bad" recursive algorithms only recurse O(n) deep at most, so you need O(n) extra space which is reasonable.

  • @Jeshtroy
    @Jeshtroy 7 лет назад +11

    16:16 Thats Erik right?

    • @nanto88
      @nanto88 6 лет назад

      Ya Erik Demaine ruclips.net/video/OQ5jsbhAv_M/видео.html

    • @devyashsanghai585
      @devyashsanghai585 6 лет назад

      What a catch!

  • @loam
    @loam 4 года назад +2

    I guess we found the reason why there is so much plastic in the ocean: those students solve too much problems and receive too much frisbee

  • @abhishektyagi4428
    @abhishektyagi4428 5 лет назад +2

    With all due respect you start monetizing your videos that will also help you