01 Knapsack Tabulation Dynamic Programming | How to build DP table

  Рет қаралды 55,475

Techdose

Techdose

Күн бұрын

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/codewithT...
TELEGRAM Group LINK: t.me/joinchat/...
=======================================================================
USEFUL LINKS:
01 Knapsack Recursion: • 01 Knapsack using Recu...
01 Knapsack Memoization: • 01 Knapsack using Memo...

Пікірлер: 98
@sakthim7160
@sakthim7160 4 жыл бұрын
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 4 жыл бұрын
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 Жыл бұрын
​@@Nieobliczalny1000 We prevent this case in this line if (i == 0 or j == 0) dp[i][j] = 0
@JitendraSingh-qd7jk
@JitendraSingh-qd7jk Жыл бұрын
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 ?
@adim1212
@adim1212 3 жыл бұрын
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 3 жыл бұрын
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.
@bhargavsai2449
@bhargavsai2449 3 жыл бұрын
within 2 or 3 yrs you will have millions of subscribers, great channel.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@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 :)
@dhananjaychoudhary7836
@dhananjaychoudhary7836 4 жыл бұрын
Thanks a lot man. This is my 4th attempt to understand knapsack DP and also the last one.
@techdose4u
@techdose4u 4 жыл бұрын
Nice :)
@Neonb88
@Neonb88 2 жыл бұрын
Congrats! Never quit!
@mikekibet1786
@mikekibet1786 3 жыл бұрын
Another masterful explanation. If I could subscribe twice, I would.
@techdose4u
@techdose4u 3 жыл бұрын
❤️
@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.
@theghostwhowalk
@theghostwhowalk 4 жыл бұрын
Never knew about heap Vs Stack memory thanks much for in-depth explanation!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@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 ???
@KhushiYadav-fo9ul
@KhushiYadav-fo9ul 8 ай бұрын
Please correct me if I am wrong , the memoization is a top- down approach and tabulation is a bottom up approach .....
@techdose4u
@techdose4u 8 ай бұрын
While it looks just the opposite but you are correct :)
@rangapavankumar79
@rangapavankumar79 4 жыл бұрын
How come 'w' in last line is it 'j' b'coz 'j' is capacity of bag?
@techdose4u
@techdose4u 4 жыл бұрын
It will be j because j is current capacity.
@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 :)
@MohamedSayed-wl5cj
@MohamedSayed-wl5cj 3 жыл бұрын
Best video on KZbin explains Knapsack problem with clear way,thanks
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@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.👏🏼👏🏼👏🏼
@ismail8973
@ismail8973 3 жыл бұрын
Your intuition explanation is on another level
@adityaojha2701
@adityaojha2701 3 жыл бұрын
We start filling table from smaller value to greater value, so this become bottom up approch. Am I right??
@Rasheed21
@Rasheed21 4 ай бұрын
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.
@aryankumar87771
@aryankumar87771 3 жыл бұрын
the sheer clarity of the explanation
@Neonb88
@Neonb88 2 жыл бұрын
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
@rishviks8987
@rishviks8987 4 жыл бұрын
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 4 жыл бұрын
Better to know both.
@pradnyamahadik5540
@pradnyamahadik5540 4 ай бұрын
Wow...really amazing explanation💯
@prathamanand1037
@prathamanand1037 3 жыл бұрын
this was a bomb video, better than everything I have ever seen
@techdose4u
@techdose4u 3 жыл бұрын
❤️
@gowthamsankaran67
@gowthamsankaran67 4 ай бұрын
Thank you so much for the explanation. I was struggling with converting recursive to iterative code. This helped me a lot.
@techdose4u
@techdose4u 4 ай бұрын
Nice :)
@samarasimhachalla3509
@samarasimhachalla3509 3 жыл бұрын
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
@nknidhi321
@nknidhi321 3 жыл бұрын
Thank you..🙏❤️
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@abhigyansharma9108
@abhigyansharma9108 3 жыл бұрын
Love You Sir
@techdose4u
@techdose4u 3 жыл бұрын
Thanks 😊
@jayanthjj
@jayanthjj 3 жыл бұрын
Thanks for this Great Video series!
@大盗江南
@大盗江南 4 ай бұрын
amazing video, thank u
@mallikarjunareddy4848
@mallikarjunareddy4848 3 жыл бұрын
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 3 жыл бұрын
Can you mention those here? I think he sorted the profit array in increasing, hence working from right to left.
@piyushkumar-wg8cv
@piyushkumar-wg8cv Жыл бұрын
You have messed up the indexes.
@nimishkumar9779
@nimishkumar9779 3 жыл бұрын
Thanks a lot! The best explanation.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@venkatadokku9190
@venkatadokku9190 4 жыл бұрын
Nice share. Can you point some questions associated with this concept ? Appreciated.
@techdose4u
@techdose4u 4 жыл бұрын
Subset sum problem
@namanvijay3514
@namanvijay3514 3 жыл бұрын
great series , following this one 👍
@techdose4u
@techdose4u 3 жыл бұрын
Great ❤️
@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 🥺🥺
@_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.
@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?
@dhanashreegodase4445
@dhanashreegodase4445 3 жыл бұрын
best video i have ever seeen..excellent..thanks alot
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@Cloud-577
@Cloud-577 2 жыл бұрын
Thank you
@santoshr4212
@santoshr4212 2 жыл бұрын
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
@garimakumari4346
@garimakumari4346 3 жыл бұрын
woow man really great..nice job
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@sarvarjuraev1376
@sarvarjuraev1376 Жыл бұрын
Thank you very much for the accurate explanation.
@andresdallarizza1526
@andresdallarizza1526 3 ай бұрын
fucking legend lov u adore u
@techdose4u
@techdose4u 3 ай бұрын
:)
@vaibhavkumargautam
@vaibhavkumargautam 2 жыл бұрын
This is the best explanation i ever came across..
@salilkumar6500
@salilkumar6500 3 жыл бұрын
Your explanation is crisp,clear n short. Very helpful to me . Keep the good work going on man,
@amansingh.h716
@amansingh.h716 3 жыл бұрын
THANKS SIR
@techdose4u
@techdose4u 3 жыл бұрын
Welcome
@kuntipatidar5191
@kuntipatidar5191 4 жыл бұрын
how your concepts are so strong?
@priyank907
@priyank907 4 жыл бұрын
Patience and practice
@debdattabiswas4902
@debdattabiswas4902 2 жыл бұрын
excellent explaination.
@codingexception6502
@codingexception6502 3 жыл бұрын
Your explanation is really good.
@mahendrasuthar7354
@mahendrasuthar7354 3 жыл бұрын
amazing bhai kya samjhaate ho mjaa aa gya thanks a lot.
@sorajkandari9603
@sorajkandari9603 3 жыл бұрын
How can u be so clear in every single word u say. awesome bro !!
@manoranjaniiit
@manoranjaniiit 3 жыл бұрын
too good
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@naman_goyal
@naman_goyal 4 жыл бұрын
Very nice
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@srikantsharma6430
@srikantsharma6430 4 жыл бұрын
Well explained!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@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 10 ай бұрын
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
@biswajitghosh9315
@biswajitghosh9315 4 жыл бұрын
Love you bro
@tech_wizard9315
@tech_wizard9315 4 жыл бұрын
Please make a roadmap for fresher to crack google in 6months
@tvrao123
@tvrao123 4 жыл бұрын
too lengthy explanation
@techdose4u
@techdose4u 4 жыл бұрын
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
@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 😃
Identification of Knapsack problems and its Types
11:28
Techdose
Рет қаралды 25 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 9 МЛН
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 67 МЛН
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,9 МЛН
01 Knapsack using Recursion | Building Intuition
18:38
Techdose
Рет қаралды 53 М.
4.5 0/1 Knapsack - Two Methods - Dynamic Programming
28:24
Abdul Bari
Рет қаралды 2,8 МЛН
01 Knapsack using Memoization | Concept of Memoization
18:03
Techdose
Рет қаралды 39 М.
A Deep Understanding of Dynamic Programming [Intro / Overview]
29:03
Dynamic Programming - 0/1 Knapsack Problem Tutorial
46:18
freeCodeCamp.org
Рет қаралды 33 М.
0-1 Knapsack problem - Inside code
10:54
Inside code
Рет қаралды 9 М.
The 0/1 Knapsack Problem (Demystifying Dynamic Programming)
20:30
Back To Back SWE
Рет қаралды 205 М.
0/1 Knapsack problem | Dynamic Programming
13:29
WilliamFiset
Рет қаралды 156 М.
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 9 МЛН