Rod Cutting - Dynamic Programming

  Рет қаралды 163,276

CSBreakdown

CSBreakdown

Күн бұрын

We look at the rod cutting algorithm, and how profits can be maximized using dynamic programming.

Пікірлер: 121
@rajeshseptember09
@rajeshseptember09 3 жыл бұрын
this is by far the best explanation out there for the "rot cutting problem"
@mentalgear3512
@mentalgear3512 8 жыл бұрын
I have been looking for a good video for this problem! This one explains it better than the rest.
@Fnr2024
@Fnr2024 9 жыл бұрын
Thank you so much for putting this together. This helped me a lot with my algorithms class.
@CSBreakdown
@CSBreakdown 9 жыл бұрын
Frank Navarro Thanks for watching! Glad that it helped.
@vaishnaviganseh2884
@vaishnaviganseh2884 3 жыл бұрын
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 9 жыл бұрын
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.
@KENILDINESHPATELBCE
@KENILDINESHPATELBCE 8 жыл бұрын
One of the best tutorial for rod-cutting problem!!
@sbshwetabhatt
@sbshwetabhatt 9 жыл бұрын
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. :-)
@amazingmanish
@amazingmanish 9 жыл бұрын
Man you made this a cakewalk. Thanks Bro. :-)
@yanlinchen9559
@yanlinchen9559 4 жыл бұрын
the best algorithm vid i ever watched
@Javii96
@Javii96 6 жыл бұрын
Great video. Helped me understand easier than the pseudo code in my textbook.
@의진이-g8k
@의진이-g8k 6 жыл бұрын
you are the only one who rescued my life from this conception dynamic programming. this concept is good but devil :( :)
@sachintsm8512
@sachintsm8512 6 жыл бұрын
This video is very good enough to understand well in rod cutting problem
@presentlymine
@presentlymine 5 жыл бұрын
This video is my life saviour. EASY AND PERFECT explanation!
@alialkhat9988
@alialkhat9988 8 жыл бұрын
Thank you so much. You have explain it way better then my instructor.. XD
@fernchh
@fernchh 5 жыл бұрын
It finally clicked, thankyou for the amazing video
@TheAInfinity
@TheAInfinity 9 жыл бұрын
You are awesome. I get it now. Thank you so much sir.Here at the Matrix, we love you!!!
@bungbang-e9n
@bungbang-e9n 8 жыл бұрын
You gotta stay calm and composed when learning DP first. Its really messy. Thanks for the video. Great work
@samirpanday4898
@samirpanday4898 4 жыл бұрын
nice advice thanks man
@pramoddy3471
@pramoddy3471 4 жыл бұрын
thank you so much sir, it help full to my exam
@Dev_God
@Dev_God 2 жыл бұрын
Clearly explained! Thank you so much for making this video!
@jinhuang7258
@jinhuang7258 Жыл бұрын
Very well explained. Thank you so much!
@deepshree9777
@deepshree9777 9 жыл бұрын
Thank You So Much!!! very well explained .. you really make it seem so easy .. now i am confident .. Keep up the good work ..
@BangladesherBiratGorurHaat
@BangladesherBiratGorurHaat Жыл бұрын
Great work and explaination Thank you
@saisrisai9649
@saisrisai9649 4 жыл бұрын
Thank you soooo much sir. I have never been able to understand this. Please do on backtracking this way. Thanks again..
@Brandonomics
@Brandonomics 9 ай бұрын
Thank you for the video!
@ymeng7442
@ymeng7442 9 жыл бұрын
Your videos are really helpful! Thank you very much!
@rummanchowdhury3807
@rummanchowdhury3807 2 жыл бұрын
Good explanation!
@_Nikhil_Bagde_
@_Nikhil_Bagde_ 8 жыл бұрын
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_ 8 жыл бұрын
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_ 8 жыл бұрын
Original Problem was only using pure recursion and not memoization takes O(2^n) exponential time. DP rocks!
@pranavn9245
@pranavn9245 3 жыл бұрын
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.
@iftekharjoy7118
@iftekharjoy7118 8 жыл бұрын
Sir karim is just awesome.upload more videos.
@abdullahshakeel1344
@abdullahshakeel1344 3 жыл бұрын
I'm looking for best one. so, here it is.
@anuvrattiku3244
@anuvrattiku3244 7 жыл бұрын
Great Video, great explanation... Thanks
@جمهوريةخرى
@جمهوريةخرى Жыл бұрын
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?
@anonymoussloth6687
@anonymoussloth6687 3 жыл бұрын
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 Жыл бұрын
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
@SenthilBalas
@SenthilBalas 9 жыл бұрын
Nice explanation
@juhithavaddineni1092
@juhithavaddineni1092 3 жыл бұрын
lots of love to you 😀
@eye23sun3
@eye23sun3 4 жыл бұрын
GREAT JOB!!
@zameetsabir543
@zameetsabir543 2 жыл бұрын
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.
@ImGuti
@ImGuti 7 жыл бұрын
Great video !
@ariashl
@ariashl Жыл бұрын
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!
@MohsinJunaidEE
@MohsinJunaidEE 3 жыл бұрын
thanks man superb jazallah
@אריאלהשקרון
@אריאלהשקרון 3 жыл бұрын
you are so good!
@TrangNguyen-jf1yj
@TrangNguyen-jf1yj 4 жыл бұрын
so so clear! tks!!
@irtizamahmud6239
@irtizamahmud6239 8 жыл бұрын
awesome video tutorial. i like it very much. thank u.
@psshatyTV
@psshatyTV 4 жыл бұрын
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?
@bartugkeskin6880
@bartugkeskin6880 5 жыл бұрын
I got it.Thank you so much.
@blindprogrammer
@blindprogrammer 5 жыл бұрын
thanks! perfect explanation.
@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 :/
@mukeshphanse1586
@mukeshphanse1586 9 жыл бұрын
It is very useful thank you so much
@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?
@islamnuralam4402
@islamnuralam4402 Жыл бұрын
Thanks a lot
@bigray712
@bigray712 8 жыл бұрын
thanks, very methodical.
@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.
@rodrigocalderon8006
@rodrigocalderon8006 Жыл бұрын
exactly
@iqraaslam7836
@iqraaslam7836 7 жыл бұрын
Good Tutorial !
@youmingxu1198
@youmingxu1198 4 жыл бұрын
Is it OK to do C(i) = { max{ C(k) + C(i-k) }, V(i) } where 1
@anonymoussloth6687
@anonymoussloth6687 3 жыл бұрын
does this work?
@gulnazbaloch29
@gulnazbaloch29 9 жыл бұрын
its an usefull video..thanks
@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 7 жыл бұрын
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 3 жыл бұрын
@@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.
@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 жыл бұрын
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
@kishor0907054
@kishor0907054 5 жыл бұрын
helpful, thank you
@jimitshah7636
@jimitshah7636 7 жыл бұрын
very nice
@SolzheBitsyn
@SolzheBitsyn 2 жыл бұрын
thanks
@manojprajapati932
@manojprajapati932 6 жыл бұрын
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
@xiaoxin0430
@xiaoxin0430 8 жыл бұрын
Thanks a lot!
@architguleria989
@architguleria989 8 жыл бұрын
The approach used here is bottom up not top down ....
@WYO_Dirtbag
@WYO_Dirtbag 8 жыл бұрын
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 7 жыл бұрын
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 жыл бұрын
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 4 жыл бұрын
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!
@prajwalacharya6048
@prajwalacharya6048 8 жыл бұрын
Awesomee!!!! Like really awesome
@avinandanganguly4466
@avinandanganguly4466 5 жыл бұрын
In the formula what the hell is 'k'?
@rachitgarg9766
@rachitgarg9766 5 жыл бұрын
Great!
@KienNguyen-uv7wj
@KienNguyen-uv7wj 8 жыл бұрын
thank you.
@Shehzad-Ahmed
@Shehzad-Ahmed 8 жыл бұрын
Thnx buddy .....
@How2GetFreeGiftCard
@How2GetFreeGiftCard 7 жыл бұрын
What happens for C(9)? We have no value for V9
@murtazanihal4181
@murtazanihal4181 7 жыл бұрын
how can u cut a 8 meter rod into 9 meter?
@shivamgupta-tk2dd
@shivamgupta-tk2dd 7 жыл бұрын
lol
@haseebhashmi4338
@haseebhashmi4338 8 жыл бұрын
Thanks sir :)
@lzmkalos
@lzmkalos 8 ай бұрын
GOD
@quanm1925
@quanm1925 3 жыл бұрын
Best
@zunairamarwat966
@zunairamarwat966 8 жыл бұрын
can i please get the source code for it ?
@aprofromuk
@aprofromuk 8 жыл бұрын
shud be easy 2 for loops - int i = 0; i < n; i++ int j = 0; j < i; j++
@akhileshjoshi8484
@akhileshjoshi8484 8 жыл бұрын
www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/
@vinodbirla765
@vinodbirla765 8 жыл бұрын
Thank you so much (Y)
@nileshjoshi5358
@nileshjoshi5358 7 жыл бұрын
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 6 жыл бұрын
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.
@deepakd6015
@deepakd6015 8 жыл бұрын
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 7 жыл бұрын
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 7 жыл бұрын
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.
@murtazanihal4181
@murtazanihal4181 7 жыл бұрын
best
@yoganandareddy4721
@yoganandareddy4721 4 жыл бұрын
wooooowwww!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
@morales9312
@morales9312 8 жыл бұрын
Brilliant!!!!!
@toprecbot
@toprecbot 2 жыл бұрын
i love u
@alanperaza9594
@alanperaza9594 4 жыл бұрын
10Q
@michaelm4110
@michaelm4110 2 жыл бұрын
thanks for wasting 15 minutes of my miserable life studying for algorithms exam
@tristanhurley9071
@tristanhurley9071 2 жыл бұрын
NO
@moatazabdelraouf4059
@moatazabdelraouf4059 5 жыл бұрын
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.
@nathanzimet434
@nathanzimet434 8 ай бұрын
not the millenial pause
@esraamohamed5601
@esraamohamed5601 5 жыл бұрын
Thank you !
@wiambenhammou9942
@wiambenhammou9942 7 жыл бұрын
Thank you!!
Polynomial vs. Pseudo-Polynomial
7:13
CSBreakdown
Рет қаралды 18 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
[Algorithms] Dynamic programming for solving the rod cutting problem
14:53
Matrix Chain Multiplication - Dynamic Programming
31:01
CSBreakdown
Рет қаралды 232 М.
Cutting a rod into pieces to maximize Profit (Dynamic Programming)
28:49
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 65 М.
Principle of Optimality - Dynamic Programming
9:26
CSBreakdown
Рет қаралды 210 М.
18. Dynamic Programming, Part 4: Rods, Subset Sum, Pseudopolynomial
1:03:45
MIT OpenCourseWare
Рет қаралды 28 М.
Longest Common Subsequence - Dynamic Programming
13:56
CSBreakdown
Рет қаралды 34 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН
Dynamic Programming - 0/1 Knapsack Problem Tutorial
46:18
freeCodeCamp.org
Рет қаралды 36 М.
Introduction to Approximation Algorithms - K Center Problem
10:38