01 Knapsack Tabulation Dynamic Programming | How to build DP table

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

Techdose

Techdose

3 жыл бұрын

This video explains the concept about how to approach a dynamic programming problem to solve using tabular DP. I have explained the concept using 01 knapsack as an example problem.I have shown the concepts and intuition in the beginning about building a table.I have also shown how to convert a recursion code to iterative code by using simple observations.At the end, I have shown the process to write Dynamic Programming code for 01 knapsack problem.If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
========================================================================
Join this channel to get access to perks:
/ @techdose4u
INSTAGRAM : / surya.pratap.k
SUPPORT OUR WORK: / techdose
LinkedIn: / surya-pratap-kahar-47b...
WEBSITE: techdose.co.in/
TELEGRAM Channel LINK: t.me/codewithTECHDOSE
TELEGRAM Group LINK: t.me/joinchat/SRVOIxWR4sRIVv5...
=======================================================================
USEFUL LINKS:
01 Knapsack Recursion: • 01 Knapsack using Recu...
01 Knapsack Memoization: • 01 Knapsack using Memo...

Пікірлер: 98
@sakthim7160
@sakthim7160 3 жыл бұрын
dp[i][j]= max( dp[i-1][j], profit[i-1]+dp[i-1][*j*-wt[i-1] ) you specified W instead of j while including the element in final else statement.
@techdose4u
@techdose4u 3 жыл бұрын
Yea right. It should be j.
@amitkumargupta6722
@amitkumargupta6722 3 жыл бұрын
@@techdose4u Its okay...concepts are more important than code..
@Nieobliczalny1000
@Nieobliczalny1000 Жыл бұрын
@@techdose4u What if j i wt[i-1] will be smaller than 0? Generally index out of bound?
@savostyanov
@savostyanov 11 ай бұрын
​@@Nieobliczalny1000 We prevent this case in this line if (i == 0 or j == 0) dp[i][j] = 0
@JitendraSingh-qd7jk
@JitendraSingh-qd7jk 11 ай бұрын
Stop copying and pinning aditya verma's code Sakthim
@vend57
@vend57 3 жыл бұрын
saw an algoexpert ad before the video. Am I buying that course after knowing that Techdose has covered 5 X more problems than Algoexpert ?
@dionisorules
@dionisorules 2 жыл бұрын
Thanks for presenting this problem so orderly, going from the decision making tree, to the recursive approach to end up translating that into the tabular iterative approach. Now this is no more black magic for me, but step by step sound reasoning. Like others said your capacity to explain these complex solutions is just brilliant and far superior to paid courses.👏🏼👏🏼👏🏼
@bhargavsai2449
@bhargavsai2449 3 жыл бұрын
within 2 or 3 yrs you will have millions of subscribers, great channel.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@dhananjaychoudhary7836
@dhananjaychoudhary7836 3 жыл бұрын
Thanks a lot man. This is my 4th attempt to understand knapsack DP and also the last one.
@techdose4u
@techdose4u 3 жыл бұрын
Nice :)
@Neonb88
@Neonb88 Жыл бұрын
Congrats! Never quit!
@34_harshdeepraghuwanshi98
@34_harshdeepraghuwanshi98 3 жыл бұрын
Sir your explanation is too much above from paid courses and also in your video i never get a doubt or if i get then you always cleared doubt by yourself later in video thanks a alot sir for providing free quality education 🙏🙏👍👍👍👍👍
@techdose4u
@techdose4u 3 жыл бұрын
Welcome bro :)
@ismail8973
@ismail8973 3 жыл бұрын
Your intuition explanation is on another level
@aryankumar87771
@aryankumar87771 3 жыл бұрын
the sheer clarity of the explanation
@theghostwhowalk
@theghostwhowalk 3 жыл бұрын
Never knew about heap Vs Stack memory thanks much for in-depth explanation!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@vaibhavkumargautam
@vaibhavkumargautam Жыл бұрын
This is the best explanation i ever came across..
@MohamedSayed-wl5cj
@MohamedSayed-wl5cj 3 жыл бұрын
Best video on KZbin explains Knapsack problem with clear way,thanks
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@sorajkandari9603
@sorajkandari9603 3 жыл бұрын
How can u be so clear in every single word u say. awesome bro !!
@sarvarjuraev1376
@sarvarjuraev1376 Жыл бұрын
Thank you very much for the accurate explanation.
@jayanthjj
@jayanthjj 3 жыл бұрын
Thanks for this Great Video series!
@mikekibet1786
@mikekibet1786 3 жыл бұрын
Another masterful explanation. If I could subscribe twice, I would.
@techdose4u
@techdose4u 3 жыл бұрын
❤️
@salilkumar6500
@salilkumar6500 2 жыл бұрын
Your explanation is crisp,clear n short. Very helpful to me . Keep the good work going on man,
@codingexception6502
@codingexception6502 3 жыл бұрын
Your explanation is really good.
@pradnyamahadik5540
@pradnyamahadik5540 Ай бұрын
Wow...really amazing explanation💯
@gowthamsankaran67
@gowthamsankaran67 Ай бұрын
Thank you so much for the explanation. I was struggling with converting recursive to iterative code. This helped me a lot.
@techdose4u
@techdose4u Ай бұрын
Nice :)
@nimishkumar9779
@nimishkumar9779 3 жыл бұрын
Thanks a lot! The best explanation.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@debdattabiswas4902
@debdattabiswas4902 2 жыл бұрын
excellent explaination.
@mahendrasuthar7354
@mahendrasuthar7354 3 жыл бұрын
amazing bhai kya samjhaate ho mjaa aa gya thanks a lot.
@vigneshvicki7020
@vigneshvicki7020 Жыл бұрын
i almost gave up trying to understand DP in tabulation, but Finally I did understand, Thank you very much bro🥹
@techdose4u
@techdose4u Жыл бұрын
Great :) welcome 😃
@prathamanand1037
@prathamanand1037 3 жыл бұрын
this was a bomb video, better than everything I have ever seen
@techdose4u
@techdose4u 3 жыл бұрын
❤️
@user-oy4kf5wr8l
@user-oy4kf5wr8l Ай бұрын
amazing video, thank u
@namanvijay3514
@namanvijay3514 3 жыл бұрын
great series , following this one 👍
@techdose4u
@techdose4u 3 жыл бұрын
Great ❤️
@dhanashreegodase4445
@dhanashreegodase4445 3 жыл бұрын
best video i have ever seeen..excellent..thanks alot
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@mallikarjunareddy4848
@mallikarjunareddy4848 2 жыл бұрын
Thanks for the explanation. It gives me an idea on how to come up with bottom up solution for dp problems . It would have been great if you had covered why we are considering items from right to left. I sat for couple of hours thinking about it and finally, I could understand the benefit of considering items from right to left over left to right
@niksgupta36
@niksgupta36 2 жыл бұрын
Can you mention those here? I think he sorted the profit array in increasing, hence working from right to left.
@ashvinimeshram5242
@ashvinimeshram5242 3 жыл бұрын
Your alll vedios are really nice.and it help me alot in my concept buliding thank u so much🙏🙏🙏🙏really good content
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@srikantsharma6430
@srikantsharma6430 3 жыл бұрын
Well explained!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@garimakumari4346
@garimakumari4346 2 жыл бұрын
woow man really great..nice job
@techdose4u
@techdose4u 2 жыл бұрын
Thanks
@Cloud-577
@Cloud-577 2 жыл бұрын
Thank you
@nknidhi321
@nknidhi321 3 жыл бұрын
Thank you..🙏❤️
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@abhigyansharma9108
@abhigyansharma9108 2 жыл бұрын
Love You Sir
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@amansingh.h716
@amansingh.h716 2 жыл бұрын
THANKS SIR
@techdose4u
@techdose4u 2 жыл бұрын
Welcome
@biswajitghosh9315
@biswajitghosh9315 3 жыл бұрын
Love you bro
@naman_goyal
@naman_goyal 3 жыл бұрын
Very nice
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@Neonb88
@Neonb88 Жыл бұрын
Wait his handwriting on a computer is so pretty. That's just the first thing I noticed. Obviously it's a good tutorial video, too
@adim1212
@adim1212 2 жыл бұрын
You and Aditya Verma both have explained DP thoroughly and both have messed up at same concept i.e. Mistaken Bottom-Up as a Top-Down approach. Did both of you shared same notes or what???
@hiteshchopra9181
@hiteshchopra9181 2 жыл бұрын
Bro I was literally finding the same in comments as I was also confused haha. But no doubt both of them teach very very good.
@manoranjaniiit
@manoranjaniiit 3 жыл бұрын
too good
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@ankitparashar8730
@ankitparashar8730 2 жыл бұрын
I have solved most of dp problem using recursion and memoization .i felt memoization dp is easier than tabalization . Should I learn tabalization dp ???
@venkatadokku9190
@venkatadokku9190 3 жыл бұрын
Nice share. Can you point some questions associated with this concept ? Appreciated.
@techdose4u
@techdose4u 3 жыл бұрын
Subset sum problem
@MadForCs16
@MadForCs16 3 жыл бұрын
Hello sir, I have one doubt, in this process we're actually moving from bottom to up ....like n=0, W=0. then why are we calling it *top-down* approach? It should be called *bottom-up*
@techdose4u
@techdose4u 3 жыл бұрын
You are right. I had made a community post regarding this. Wish you were there 😅 But yea, it's bottom up.
@KhushiYadav-fo9ul
@KhushiYadav-fo9ul 5 ай бұрын
Please correct me if I am wrong , the memoization is a top- down approach and tabulation is a bottom up approach .....
@techdose4u
@techdose4u 5 ай бұрын
While it looks just the opposite but you are correct :)
@samarasimhachalla3509
@samarasimhachalla3509 2 жыл бұрын
When deciding about which one to go ahead with Memoization or Tabulation methods. Try to identify the no.of values in the DP table or array that is required to solve the problem. If the number is very less compared to the total size, then go ahead with Memoization for better time complexity because in the Tabulation method it'll compute the whole table, then give you the output. And yeah, if the number of values that need to be computed in the table or array, is not very small when compared to the total size, then yeah go ahead with tabulation. Credits: GFG
@santoshr4212
@santoshr4212 Жыл бұрын
Friends, can someone explain in which case memoization will be useful because unlike Fibonacci I dont see a case where same value/computation can be repeated because in each case weight may be different
@rangapavankumar79
@rangapavankumar79 3 жыл бұрын
How come 'w' in last line is it 'j' b'coz 'j' is capacity of bag?
@techdose4u
@techdose4u 3 жыл бұрын
It will be j because j is current capacity.
@rishviks8987
@rishviks8987 3 жыл бұрын
Sir I'm good at memoisation but I don't have any idea about tabulation coz I nerver used it. Should one know both of them?
@techdose4u
@techdose4u 3 жыл бұрын
Better to know both.
@imukai
@imukai 2 жыл бұрын
I get that this method gives you the total profit at the end of the table -- but how do you determine which of the elements in the set were selected to arrive at that sum?
@smitkarwatkar03
@smitkarwatkar03 7 ай бұрын
use a prev array which will store the indexes of each optimal step. at the end you would get all the elements in your optimal solution
@heedererroger9324
@heedererroger9324 3 жыл бұрын
your approach to get maximum value is direction which is from right to left. But your table structure is left-top to right bottom to find maximum value. It's confusing... am I misunderstanding?
@kuntipatidar5191
@kuntipatidar5191 3 жыл бұрын
how your concepts are so strong?
@priyank907
@priyank907 3 жыл бұрын
Patience and practice
@adityaojha2701
@adityaojha2701 3 жыл бұрын
We start filling table from smaller value to greater value, so this become bottom up approch. Am I right??
@Rasheed21
@Rasheed21 Ай бұрын
Not really. Tabulation/Iteration is Bottom-Up even if you interate in decreasing order. Recursivion+Memoization is Top-Down even if your recusion is in increasing order.
@piyushkumar-wg8cv
@piyushkumar-wg8cv Жыл бұрын
You have messed up the indexes.
@andresdallarizza1526
@andresdallarizza1526 4 күн бұрын
fucking legend lov u adore u
@techdose4u
@techdose4u Күн бұрын
:)
@_SajjadHossainTalukder
@_SajjadHossainTalukder 3 жыл бұрын
A bottom-up algorithm "starts from the beginning," while a recursive algorithm often "starts from the end and works backwards" . That's why recursive algorithm is known as top down . U wrongly interpreted this top down Approach. It may be Bottom-Up approach. Please Make it clear.
@tech_wizard9315
@tech_wizard9315 3 жыл бұрын
Please make a roadmap for fresher to crack google in 6months
@learnersparadise7492
@learnersparadise7492 3 жыл бұрын
You copy pasted content of Mr Aditya Verma in English, just...even his calling of bottom up as top down is copied man....do some original work please 🥺🥺
@tvrao123
@tvrao123 3 жыл бұрын
too lengthy explanation
@techdose4u
@techdose4u 3 жыл бұрын
It was basics so it went long.
@Dryicicles
@Dryicicles 3 жыл бұрын
lmao then shut up and dont learn
@manishkumartyagi1815
@manishkumartyagi1815 3 жыл бұрын
Looks like copied from the videos of Aditya Verma :D , exactly same.......... hahahahahaha
Identification of Knapsack problems and its Types
11:28
Techdose
Рет қаралды 24 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Sigma Girl Past #funny #sigma #viral
00:20
CRAZY GREAPA
Рет қаралды 30 МЛН
Please be kind🙏
00:34
ISSEI / いっせい
Рет қаралды 191 МЛН
01 Knapsack using Recursion | Building Intuition
18:38
Techdose
Рет қаралды 51 М.
4.5 0/1 Knapsack - Two Methods - Dynamic Programming
28:24
Abdul Bari
Рет қаралды 2,7 МЛН
Lecture 19: Dynamic Programming I: Fibonacci, Shortest Paths
51:47
MIT OpenCourseWare
Рет қаралды 2,8 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 611 М.
The 0/1 Knapsack Problem (Demystifying Dynamic Programming)
20:30
Back To Back SWE
Рет қаралды 202 М.
0/1 Knapsack problem | Dynamic Programming
13:29
WilliamFiset
Рет қаралды 142 М.
The Change Making Problem - Fewest Coins To Make Change Dynamic Programming
23:12
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
3.1 Knapsack Problem - Greedy Method
15:30
Abdul Bari
Рет қаралды 2,2 МЛН