Rod Cutting - Dynamic Programming

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • We look at the rod cutting algorithm, and how profits can be maximized using dynamic programming.

КОМЕНТАРІ • 120

  • @mentalgear3512
    @mentalgear3512 7 років тому +22

    I have been looking for a good video for this problem! This one explains it better than the rest.

  • @Fnr2024
    @Fnr2024 9 років тому +27

    Thank you so much for putting this together. This helped me a lot with my algorithms class.

    • @CSBreakdown
      @CSBreakdown  9 років тому +7

      Frank Navarro Thanks for watching! Glad that it helped.

  • @rajeshseptember09
    @rajeshseptember09 2 роки тому +1

    this is by far the best explanation out there for the "rot cutting problem"

  • @KENILDINESHPATELBCE
    @KENILDINESHPATELBCE 7 років тому +1

    One of the best tutorial for rod-cutting problem!!

  • @amazingmanish
    @amazingmanish 8 років тому +14

    Man you made this a cakewalk. Thanks Bro. :-)

  • @vaishnaviganseh2884
    @vaishnaviganseh2884 2 роки тому

    I wish I had come across this video earlier and not after 5 hours of breaking my head on this problem. thanks mate

  • @mayurkulkarni755
    @mayurkulkarni755 8 років тому +1

    Thank you very much! The first time I saw this problem in CLRS it got the shit out of me. You make it seem so easy! Continue your good work.

  • @sbshwetabhatt
    @sbshwetabhatt 9 років тому +2

    I was puzzled with the Rod Cut Algorithm in my class. Thank you so much for putting it together in such an easy way. It helped me a lot. :-)

  • @Javii96
    @Javii96 5 років тому +1

    Great video. Helped me understand easier than the pseudo code in my textbook.

  • @yanlinchen9559
    @yanlinchen9559 4 роки тому

    the best algorithm vid i ever watched

  • @sachintsm8512
    @sachintsm8512 5 років тому

    This video is very good enough to understand well in rod cutting problem

  • @Nov-qr7dd
    @Nov-qr7dd Рік тому

    thank you for teaching, you too have a great day, salute!

  • @의진이-g8k
    @의진이-g8k 5 років тому +1

    you are the only one who rescued my life from this conception dynamic programming. this concept is good but devil :( :)

  • @presentlymine
    @presentlymine 5 років тому +1

    This video is my life saviour. EASY AND PERFECT explanation!

  • @alialkhat9988
    @alialkhat9988 8 років тому +2

    Thank you so much. You have explain it way better then my instructor.. XD

  • @ymeng7442
    @ymeng7442 9 років тому +1

    Your videos are really helpful! Thank you very much!

  • @bungbang-e9n
    @bungbang-e9n 7 років тому +2

    You gotta stay calm and composed when learning DP first. Its really messy.
    Thanks for the video. Great work

  • @Dev_God
    @Dev_God 2 роки тому

    Clearly explained! Thank you so much for making this video!

  • @TheAInfinity
    @TheAInfinity 8 років тому

    You are awesome. I get it now. Thank you so much sir.Here at the Matrix, we love you!!!

  • @jinhuang7258
    @jinhuang7258 Рік тому

    Very well explained. Thank you so much!

  • @FernandoChristyanto
    @FernandoChristyanto 4 роки тому

    It finally clicked, thankyou for the amazing video

  • @Brandonomics
    @Brandonomics 5 місяців тому

    Thank you for the video!

  • @deepshree9777
    @deepshree9777 8 років тому

    Thank You So Much!!! very well explained .. you really make it seem so easy .. now i am confident .. Keep up the good work ..

  • @anonymoussloth6687
    @anonymoussloth6687 3 роки тому +2

    I am a bit confused. Shouldn't C(2) be equal to C(1) + C(1)? and for C(n) it should be max[C(i) + C(n-i)] ? since wouldn't we want the most profitable way to cut BOTH [0..i] and [i+1...n] sections of the rod? Why are we only taking the optimal way to cut one section plus the normal price of cutting the other? Why not the optimal way to cut that also? Meaning, Shouldn't we do C(K) instead of V(K)? Someone plz explain why we are only getting the C() value for only one section of the division and the V() value for the other when I think it should be C() value for both

    • @flaggern7058
      @flaggern7058 10 місяців тому

      I came looking for an answer to this caus I agree with you, but your comment is 2 years old so i guess i'll never find out

  • @BangladesherBiratGorurHaat
    @BangladesherBiratGorurHaat Рік тому

    Great work and explaination Thank you

  • @architguleria989
    @architguleria989 8 років тому +44

    The approach used here is bottom up not top down ....

    • @WYO_Dirtbag
      @WYO_Dirtbag 7 років тому +1

      My professor is not specifying if it has to be top down or bottom up on my test so I will choose this way.

    • @user-px2jq1bm8t
      @user-px2jq1bm8t 7 років тому

      Why bottom up

    • @chrisklecker
      @chrisklecker 6 років тому +3

      I was just about to say this. This is bottom up because we are starting from the most primitive of values C(1) and working our way up to the top most value C(j). Most memoization algorithms work from bottom up like the rod cutting programming.

    • @akashdutta1620
      @akashdutta1620 6 років тому +10

      This is not bottom up, its actually top down approach because the function will be recursive, will start from N continuous call till 0, then from 0 it will keep on solving to top, understand the concept.
      Anyway, this process is called memoization and its mean top down.
      This can also be solved using tabulation, no recursive call on this case, the loop will simply start from 0 continue to N, that is bottom up.
      Now u get it?

    • @eye23sun3
      @eye23sun3 3 роки тому +1

      There were 45 people who have zero CS knowledge and don't know the difference between top down and bottom up approach. Unfortunately, these are the same people who get hired by FAANG. This is TOP DOWN!

  • @saisrisai9649
    @saisrisai9649 4 роки тому

    Thank you soooo much sir. I have never been able to understand this. Please do on backtracking this way. Thanks again..

  • @abdullahshakeel1344
    @abdullahshakeel1344 3 роки тому +1

    I'm looking for best one. so, here it is.

  • @pramoddy3471
    @pramoddy3471 3 роки тому

    thank you so much sir, it help full to my exam

  • @_Nikhil_Bagde_
    @_Nikhil_Bagde_ 7 років тому +2

    15.8 you mentioned its top down approach, I think this is bottom up approach, isn't it?
    we are considering from the first piece and moving top to get bigger and bigger piece by combining smaller pieces.

    • @_Nikhil_Bagde_
      @_Nikhil_Bagde_ 7 років тому

      Oh right, it depends on if I use the recursive approach with memoization I will have to go Top Down and solve the base case -> Store and Use it. Makes sense. O (n^2) for n length + n recursive calls.
      The Later case with the Bottom-up approach, we use 2 for loops. O (n^2)

    • @_Nikhil_Bagde_
      @_Nikhil_Bagde_ 7 років тому

      Original Problem was only using pure recursion and not memoization takes O(2^n) exponential time.
      DP rocks!

    • @pranavn9245
      @pranavn9245 2 роки тому

      In memoization, there is the advantage of solving only the necessary of the subproblems but the overhead of increased space due to the recursive call stack. In tabulation, or bottom up approach, where all the smaller subproblems are solved first and thus the solution to the required problem found, there is the overhead of solving unnecessary subproblems but the advantage of reduced space complexity.

  • @juhithavaddineni1092
    @juhithavaddineni1092 3 роки тому

    lots of love to you 😀

  • @rummanchowdhury3807
    @rummanchowdhury3807 2 роки тому

    Good explanation!

  • @anuvrattiku3244
    @anuvrattiku3244 7 років тому

    Great Video, great explanation... Thanks

  • @iftekharjoy7118
    @iftekharjoy7118 8 років тому

    Sir karim is just awesome.upload more videos.

  • @MohsinJunaidEE
    @MohsinJunaidEE 2 роки тому

    thanks man superb jazallah

  • @eye23sun3
    @eye23sun3 3 роки тому

    GREAT JOB!!

  • @SenthilBalas
    @SenthilBalas 8 років тому

    Nice explanation

  • @blindprogrammer
    @blindprogrammer 5 років тому

    thanks! perfect explanation.

  • @irtizamahmud6239
    @irtizamahmud6239 7 років тому

    awesome video tutorial. i like it very much.
    thank u.

  • @ImGuti
    @ImGuti 7 років тому

    Great video !

  • @ariashl
    @ariashl 10 місяців тому

    that was really good tnx, Could you pls put presentation file for us too,that would be great

  • @koenburg9751
    @koenburg9751 5 років тому

    Yeah my professors' explaination was utter shite, thanks for making me understand!

  • @bigray712
    @bigray712 8 років тому

    thanks, very methodical.

  • @bartugkeskin6880
    @bartugkeskin6880 4 роки тому

    I got it.Thank you so much.

  • @TrangNguyen-jf1yj
    @TrangNguyen-jf1yj 4 роки тому

    so so clear! tks!!

  • @אריאלהשקרון
    @אריאלהשקרון 3 роки тому

    you are so good!

  • @mukeshphanse1586
    @mukeshphanse1586 9 років тому

    It is very useful thank you so much

  • @FreedomForKashmir
    @FreedomForKashmir 5 років тому

    thank you so much man
    you are great
    Much love and God bless

    • @blindprogrammer
      @blindprogrammer 5 років тому

      Are you still alive? I think you were neutralized by the Indian military in Kashmir :/

  • @zameetsabir543
    @zameetsabir543 Рік тому

    I was trying to understand this problem and couldn't wrap my head around the mechanism. Now, finally after watching this video finally understood the mechanism used 🥲. Thank you very much 🥲❤

  • @aliashoori8274
    @aliashoori8274 4 роки тому

    I liked that first 5 mins - killed the complexity for me. Thanks.

  • @iqraaslam7836
    @iqraaslam7836 7 років тому

    Good Tutorial !

  • @gulnazbaloch29
    @gulnazbaloch29 9 років тому

    its an usefull video..thanks

  • @kishor0907054
    @kishor0907054 5 років тому

    helpful, thank you

  • @esraamohamed5601
    @esraamohamed5601 5 років тому

    Thank you !

  • @islamnuralam4402
    @islamnuralam4402 10 місяців тому

    Thanks a lot

  • @prajwalacharya6048
    @prajwalacharya6048 7 років тому

    Awesomee!!!! Like really awesome

  • @dstgre
    @dstgre 6 років тому

    Why does this work? When you take a Vk and to it V(i-k) wouldn't V(i-k) already have counted Vk using a different combination?

  • @xiaoxin0430
    @xiaoxin0430 8 років тому

    Thanks a lot!

  • @psshatyTV
    @psshatyTV 3 роки тому

    Why are you doing V_3+C(5) than V_5 + C(3) and not just C(3) + C(5)? It seems to me that in some cases C(3) + C(5) can be bigger than max(V_3+C(5) ,V_5 + C(3) ) and your solution may not be optimal, am I wrong?

  • @tonyaiello9811
    @tonyaiello9811 9 років тому

    Very good demonstration. However to clearly communicate the reuse of value for dynamic programming the whole table would be useful. The demonstration shows the repeated calculation at each step rather than showing the lookup of the table from the previous steps.

  • @جمهوريةخرى
    @جمهوريةخرى Рік тому

    i have a question when finding c8 why when we cut it 4 by 4 its 19 isnt a length 4 worth according to the dp array 10 then it would be 20 right?

  • @jimitshah7636
    @jimitshah7636 6 років тому

    very nice

  • @manojprajapati932
    @manojprajapati932 5 років тому +2

    this is only reverse engineering of the root problem. The business actually start from scratch like their shampoo product can be distribute in 10ml, 20ml, 250ml, 500ml, 1ltr qty now the possibility of buying

  • @haseebhashmi4338
    @haseebhashmi4338 7 років тому

    Thanks sir :)

  • @kirancobi
    @kirancobi 7 років тому

    Dear CSBreakdown, How did you derive the recurrence relation?(i.e C(i) = Max{V of k + C(i-k)} . This is not obvious or intuitive to me.

    • @Tierprot
      @Tierprot 7 років тому +2

      Thats pretty simle to understand if you will think about it carefully. What is 'i'? Its the lenght of a rod. What is 'k'? 'k' is the size of a rod we can cut off. What does Vk + C(i-k) means? It means we cut a subrod of size 'k' (which price is Vk) and we left with a reminder of a rod with size i-k. Now what is the price of a reminder of size i-k - we already calculated it in array of prices C, it is C(i-k) and we come to the recurrent formula

  • @KienNguyen-uv7wj
    @KienNguyen-uv7wj 8 років тому

    thank you.

  • @deepakd6015
    @deepakd6015 7 років тому +5

    Shouldn't it be max{Ck+C(i-k)} ?

    • @bd189a55
      @bd189a55 7 років тому

      Yes, I think it should be max{Ck+C(i-k)}.

    • @rickdev
      @rickdev 7 років тому

      I don't think so...let's say your statement is indeed true, then why did they bother to give us a price array?.. You can't build a revenue array if you don't use the input price array...You can't either demonstrate the optimal sub structure proof.. that ad-hoc thing will return the same thing unless you change the k..Good luck ;)

    • @bd189a55
      @bd189a55 7 років тому

      You are right. That was wrong, the price was not used. Later on, I found in order to make max{Ck+C(i-k)} work, I've to pre-load C(1)=1, C(5)=1, C(25)=1....before the iteration starts, so the algo knows when to use one coin instead of many.

    • @chrisklecker
      @chrisklecker 6 років тому +1

      C(k) and V(k) can represent the same thing. It's not incorrect but to say C(k) could clear up confusion about where that value comes from.

    • @joshuawest3247
      @joshuawest3247 6 років тому +3

      No... what they had on the screen was right, if you took C(k), you would be looking at the optimal values not the price for the specific value of a rod of x length. Vk is looking at the other side of this addition which is the static original values. The optimal substructure part is the C(i-k). So what you're doing is adding one part optimal substructure and one part original value to determine the NEXT single best cut to make, so original values, Vk, still come into play. Subtle point, but this had a few too many up votes and the author is not keeping up.

  • @Shehzad-Ahmed
    @Shehzad-Ahmed 8 років тому

    Thnx buddy .....

  • @jessiemanak9767
    @jessiemanak9767 8 років тому

    in this case wouldn't it be much simpler to take a ratio of cost/length for each sublength and apply the highest ratio to the total length we want to cut until the remaining piece is smaller than the highest ratio piece and then cutting the next highest ratio length that we can... e.g. length 6 has the highest ratio so we prefer to cut 6-lengths from the rod until we have less than length 6 remaining then we cut the next highest ratio length until we have cut all??

    • @joshuawest3247
      @joshuawest3247 6 років тому +1

      This is the greedy algorithm for this problem. It does not guarantee an optimal solution, however. And you want more money for your rod don't you? You worked hard for that rod. You better cut that rod the best possible way you can.

    • @pranavn9245
      @pranavn9245 2 роки тому

      @@joshuawest3247 Hi. I often come across this statement that a greedy algorithm does not "guarantee" an optimal solution. Could you please explain why this is so? An algorithm is supposed to work out is it not? If a greedy algorithm does not produce an an optimal solution, that would make it in*correct* and not merely in*efficient*, correct? Also, could you give an instance of the rod - cutting problem where the greedy algorithm does not work?
      Hope for a reply, thanks.

  • @youmingxu1198
    @youmingxu1198 4 роки тому

    Is it OK to do C(i) = { max{ C(k) + C(i-k) }, V(i) } where 1

  • @avinandanganguly4466
    @avinandanganguly4466 5 років тому

    In the formula what the hell is 'k'?

  • @rachitgarg9766
    @rachitgarg9766 5 років тому

    Great!

  • @SolzheBitsyn
    @SolzheBitsyn 2 роки тому

    thanks

  • @vinodbirla765
    @vinodbirla765 8 років тому

    Thank you so much (Y)

  • @nileshjoshi5358
    @nileshjoshi5358 7 років тому +1

    I think max value of k=floor(i/2) should be enough. K do not required to go all the way to i.

    • @christernilsson1
      @christernilsson1 5 років тому

      I agree. Also, c[] should be initialized with v[]. I don't think v[4]==9 should be used when we know c[4]==10.

  • @How2GetFreeGiftCard
    @How2GetFreeGiftCard 7 років тому

    What happens for C(9)? We have no value for V9

  • @morales9312
    @morales9312 8 років тому

    Brilliant!!!!!

  • @lzmkalos
    @lzmkalos 4 місяці тому

    GOD

  • @zunairamarwat966
    @zunairamarwat966 7 років тому

    can i please get the source code for it ?

    • @aprofromuk
      @aprofromuk 7 років тому

      shud be easy 2 for loops -
      int i = 0; i < n; i++
      int j = 0; j < i; j++

    • @akhileshjoshi8484
      @akhileshjoshi8484 7 років тому

      www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/

  • @quanm1925
    @quanm1925 3 роки тому

    Best

  • @murtazanihal4181
    @murtazanihal4181 7 років тому

    best

  • @yoganandareddy4721
    @yoganandareddy4721 4 роки тому

    wooooowwww!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11

  • @toprecbot
    @toprecbot Рік тому

    i love u

  • @michaelm4110
    @michaelm4110 2 роки тому

    thanks for wasting 15 minutes of my miserable life studying for algorithms exam

  • @moatazabdelraouf4059
    @moatazabdelraouf4059 4 роки тому

    While this explanation is nice, it does not support multiple cuts (ex: 1,1,2 for 4). Although not applicable in this example, a lot of the time, the optimal price is based off of more than just 1 cut.

  • @alanperaza9594
    @alanperaza9594 4 роки тому

    10Q

  • @tristanhurley9071
    @tristanhurley9071 2 роки тому

    NO

  • @nathanzimet434
    @nathanzimet434 4 місяці тому

    not the millenial pause

  • @wiambenhammou9942
    @wiambenhammou9942 7 років тому

    Thank you!!