Dynamic Programming | Set 10 (0-1 Knapsack Problem) | GeeksforGeeks

  Рет қаралды 285,726

GeeksforGeeks

GeeksforGeeks

Күн бұрын

Пікірлер: 94
@158_aniketmallick6
@158_aniketmallick6 5 жыл бұрын
I think this video needs to be made again by someone else.... can't explain any thing clearly. plss guys see into it.
@surendharrudra1974
@surendharrudra1974 3 жыл бұрын
Good efforts, fail to follow. Explanation could be improved
@shashankpandey374
@shashankpandey374 2 жыл бұрын
worst explaination can only be find at gfg YT😓😓
@neelalexpaul
@neelalexpaul 7 жыл бұрын
sorry to say this, but the explanation can be made better, comparing with the qulaity of presentation in the previous 6 videos in the same playlist which made dynamic programming look too simple :)
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you for your feedback Neel. We shall try to keep simpler explanations in future videos. Can you provide some more feedback? Can you please pinpoint a few things that can be improved in this video? It will help us in understanding the gap better.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
I made an explanation on my channel
@haq_se_dkp
@haq_se_dkp 5 жыл бұрын
@@BackToBackSWE Yours is the best channel I have seen so far. I would urge all of those interested to check out @Back To Back SWE. The tenor, modulation explanation and intuition are simply breathtaking.
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
@@haq_se_dkp hey haha
@SaishGersappa
@SaishGersappa 7 жыл бұрын
The space complexity for the recursive solution is not O(1). Considering the stack usage, the space complexity is the depth of the recursive tree, O(N).
@boldschool6308
@boldschool6308 7 жыл бұрын
The way you have explained, unfortunately, shows that you are fed up with what you are doing...
@abhishektiwari1989
@abhishektiwari1989 5 жыл бұрын
Stop criticizing.
@jinisha6485
@jinisha6485 4 жыл бұрын
Then don’t watch
@abmallick
@abmallick 5 жыл бұрын
New video with better explanation. kzbin.info/www/bejne/r6jMeWCwh61ko6M
@maheshvangala8472
@maheshvangala8472 5 жыл бұрын
Dear geeksforgeeks if you had included an explanation using tabular method before implementing code this will go to next level
@engineer5851
@engineer5851 Жыл бұрын
Implement hill climbing algorithm for knapsack - code please
@mrblacksanta
@mrblacksanta 5 жыл бұрын
You are literally reading out whats in your site. Cmon man , dont post just for watch time .
@ganeshchandrameesala257
@ganeshchandrameesala257 3 жыл бұрын
I did it like this. Will this work for all values? from itertools import combinations dic = {} for i,j in zip(list(map(int,input().split(','))),list(map(int,input().split(',')))): dic[j] = i lim = int(input()) finlst = [] for i in range(len(dic),0,-1): temp = list(combinations(list(dic.keys()),i)) for j in temp: if sum(j)
@vishalpatil4983
@vishalpatil4983 4 жыл бұрын
One of the worst Explaination I ever heard
@nitishdash
@nitishdash 7 жыл бұрын
Compared to the previous tutorials this one is really difficult to understand. Especially the optimal problem. Using k[][]
@souravmandal7527
@souravmandal7527 6 жыл бұрын
Knapsack problem can be explained much more easily using the table
@guptagopal
@guptagopal 5 жыл бұрын
first example solution is 240 not 220
@meenumeena919
@meenumeena919 4 жыл бұрын
Why weight array was not sorted ??We have to sort the weight array
@meenumeena919
@meenumeena919 4 жыл бұрын
@geeksforgeeks
@vamsikrishnasai1682
@vamsikrishnasai1682 2 жыл бұрын
What Is n in function?
@AmitKumar-we8dm
@AmitKumar-we8dm 4 жыл бұрын
How to get the list of items which are selected? Your function simply calculates the final value. It would have been great if you cover these cases as well...
@arnabkaycee
@arnabkaycee 7 жыл бұрын
explanation is very confusing.
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you for your feedback, Arnab. We might be posting a new video soon. Could you please point out a few things that you found hard to understand? For example, is it the code explanation, dry run?
@MukeshRajput1982
@MukeshRajput1982 6 жыл бұрын
Very Informative........... kzbin.info/door/oscfxTBY93lYauulG-fBRw www.mukeshrajput102.com/
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
I cover this on my channel friend
@vetiarvind
@vetiarvind 5 жыл бұрын
such an easy problem explained like you're deriving e=mc2. :-/
@bhanuprakashchinthakayala8123
@bhanuprakashchinthakayala8123 6 жыл бұрын
sir actually in recursion i got full clarity but when its comes to the dynamic programing i'm not able get how many times does the 'w' for loop(2 for loop is iterating) can you it ..?
@surajpark
@surajpark 5 жыл бұрын
The maximum possible value is 300 if you add a weight of 10 upto five times which will not going to break the constraint. can anyone explain how this 220 value could be the answer but not 300?
@HallaBool
@HallaBool 7 жыл бұрын
It can solved with a 1D array: int[] K = new int [W+1]; for(int i=0; i=wt[i];j--){ K[j] = Math.max(val[i]+K[j-wt[i]], K[j]); } } return K[W];
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Yes, Someshwar, it can be solved using a 1-D array too. And, we should use a 1-D array when the input size is going to be large. This way we can reduce space complexity from O(nW) to O(W).
@tanmaygoel2880
@tanmaygoel2880 3 жыл бұрын
The explanation for the recursive solution was good but I don't know what happened when it came to DP. The explanation for the DP part could be better.
@hrishabhg
@hrishabhg 4 жыл бұрын
What if all the weights are higher than asked weight. Should we consider memoization instead of a bottom-up approach?
@fakhriddinmakhmadiyorov7269
@fakhriddinmakhmadiyorov7269 4 жыл бұрын
with recursion it seems rather easy, thank you
@chainsinghpawar9138
@chainsinghpawar9138 3 жыл бұрын
Easy 😂
@soumalyasahoo2664
@soumalyasahoo2664 5 жыл бұрын
The dry run of the dp approach is solved in a wrong fashion.In the code you are either taking the i-1 th item or ignoring it then proceeding further till n-1 the item.But in the dry run you first considered the n-1 th item then you went down to 0. Am I correct?
@UsualParadox
@UsualParadox 7 жыл бұрын
Hey guys, first of all, thanks for all the great content you've put out! Amazing, thanks! I do have a question about the code above: everything pretty straight forward until it gets to this line: M[j][i] = max(M[j][i], M[j-1][i-weight[j]]+value[j]); more specifically: [i-weight[j]]. My question is how is this working? how is i minus the value store in weight[j] giving us an index within range?
@prathamkushwah1670
@prathamkushwah1670 2 жыл бұрын
it is not giving us index within bounds, and so c++ gives random large negative garbage values for that index, so the max value selected is always 0 or any other (and not one with index[ i - weight[i] ]
@23loges1
@23loges1 7 жыл бұрын
Good videos. one suggestion... instead of directly jumping on to the solution.... please provide the reason for the particular approach in a real life logic sense, as it would help understand why the solution is used, than just how the solution works. These videos really help lot of people.. great service guys...keep up the good work...
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you for your feedback, Mark! :) We will keep in mind your suggestion.
@elmesiasyourpapi
@elmesiasyourpapi 8 жыл бұрын
Thanks for the videos. Can you do a reproduction list just for dynamic programming?
@GeeksforGeeksVideos
@GeeksforGeeksVideos 8 жыл бұрын
You're welcome. Yes. We're working on adding more videos.
@AshishSharma-li1dq
@AshishSharma-li1dq 5 жыл бұрын
very bad explanation
@AshishGupta-rh3jf
@AshishGupta-rh3jf 6 жыл бұрын
not well explained and presenter is eating during presentation .. which is very awkward
@HuongLe-qo7xw
@HuongLe-qo7xw 4 жыл бұрын
How to include the list of weight of final result in python?
@TheGreatOne428
@TheGreatOne428 7 жыл бұрын
the mic quality is bad. I would have read from a script to ensure I do not stutter while speaking.
@somyamishra5538
@somyamishra5538 5 жыл бұрын
By using tabulation explanation can be made better..
@sahulrajhansa8363
@sahulrajhansa8363 4 жыл бұрын
I think creating a basic visualization of the 2d array used in dynamic programming will help us understand this problem better
@jubaer.hossain
@jubaer.hossain 6 жыл бұрын
The explanation doesn't make any sense! Confusing
@sandeshavhad7737
@sandeshavhad7737 8 жыл бұрын
I am referring your site for dynamic programming, its very helpful Please post more videos on Dynamic Programming (algorithm and its implementation in Java). Thank You :)
@GeeksforGeeksVideos
@GeeksforGeeksVideos 8 жыл бұрын
Thank you, Sandesh. We're working on adding more videos.
@ShivamKumar-gy4tz
@ShivamKumar-gy4tz 5 жыл бұрын
@@GeeksforGeeksVideos Ir's the best portal for CSE students in the world
@soumalyasahoo2664
@soumalyasahoo2664 5 жыл бұрын
Why didn't you use the table to explain that?
@neeleshrajpoot1493
@neeleshrajpoot1493 5 жыл бұрын
very poor explanation
@shubhamdhiman5198
@shubhamdhiman5198 7 жыл бұрын
dude you are not at all clear. The explanation is far more simpler than this video. P.S: Please turn off the fan
@YouTuber-lb9ot
@YouTuber-lb9ot 7 жыл бұрын
Not a good presentation.. seems to be novice who is rushing into solution... could have taken a retake with something better.. good luck next time.
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thanks for the feedback. It is one of the earliest of our videos. You will find better presentation in the recent ones. :)
@tedsprogz
@tedsprogz 7 жыл бұрын
I mean this in the nicest way possible, but i cannot understand anything you are saying. Your accent is too thick for me.
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
It's perfectly fine to say that, Theodore. Thank you for your feedback. I had planned to add subtitles to this video but somehow time keeps flying off my hands. Anyway, I'll add subtitles to this video asap.
@danieldil6198
@danieldil6198 7 жыл бұрын
The complexity is 2^n but on the example tree you have 2^n+1 function calls. Why is that?
@vinaykumar5508
@vinaykumar5508 4 жыл бұрын
Thanks a lot...
@sivar4300
@sivar4300 7 жыл бұрын
If you don't depict it with 2D array, its very hard for people to understand.
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you for your feedback, Shiva. We shall incorporate this in the future video. This was our first video on Dynamic Programming, naturally, it's not as good as our recent videos on Dynamic Programming. You can see the 1D/2D arrays in our videos on LIS: kzbin.info/www/bejne/hKSXfXabmrR5iZY LCS: kzbin.info/www/bejne/fpi4gIp4ZbinhKc
@736939
@736939 8 жыл бұрын
Hello please tell me on 6:29 why in second bracket when you didn't included n-th element it is n-1. I think it should be n-2 on second bracket - because you didn't include the last element.
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Hi Sam, The 'n-1' over there signifies the remaining number of items to pick from (and not the last element). If you notice, in the first case, when we are including the nth item, we have written val[n-1] (signifying the nth element in the array) and in the function call on the right we have 'n-1' (signifying the remaining number of items to be evaluated to include or exclude in the knapsack.) So, in the second case, where we don't include the nth item, we have not written val[n-1] (the nth element) and in the bracket, we have written 'n-1' (with same meaning as above).
@TravellingBeast123
@TravellingBeast123 5 жыл бұрын
good job
@deepchhatbar3237
@deepchhatbar3237 7 жыл бұрын
If we select 2 times 20 and one time 10.....we will get 100+100+60= 260......i think this is the correct answer..
@indowestlife
@indowestlife 6 жыл бұрын
We cannot select an item twice
@deepchhatbar3237
@deepchhatbar3237 6 жыл бұрын
Aakash Verma yeah i got it afterwards..👍
@bhargavreddy7038
@bhargavreddy7038 6 жыл бұрын
forgiven 2:31
@tedsprogz
@tedsprogz 7 жыл бұрын
How do i allow duplicates? say i want to add an item twice
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Please take a look at this: code.geeksforgeeks.org/3m3Fl5 I have added two items having the same value and the same weight. The program gives correct output. It does allow duplicates as long as it's there in your input array. You don't need to handle it as a special case. Does this answer your query?
@shubhambhattacharya6046
@shubhambhattacharya6046 7 жыл бұрын
Nice one
@yohosuff
@yohosuff 7 жыл бұрын
First of all, thanks for these videos. They are great! :) That being said, I was hoping for a demonstration of how to manually fill in the dynamic programming grid. I'm sure one could work it out from the provided code, but it's nice to see an actual example. I find it very effective for understanding the problem. An example of what I'm talking about is in "Dynamic Programming | Set 4 (Longest Common Subsequence) | GeeksforGeeks" at 2:02 (kzbin.info/www/bejne/fpi4gIp4ZbinhKcm2s).
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you, Joey! Good to hear you liked the videos. :) This video was actually prepared a long time back before we made the other videos. And, we're aware that it's lacking the dry run where we fill the table. I will try to add another video with the dry run in the coming few weeks.
@yohosuff
@yohosuff 7 жыл бұрын
Awesome! A dry run would be great. Thanks! 😀
@RafiqulIslam-hr5on
@RafiqulIslam-hr5on 8 жыл бұрын
10+10+10+10+10=5*60=300 is it wrong ? i think this is the answer ..
@GeeksforGeeksVideos
@GeeksforGeeksVideos 8 жыл бұрын
Yes, Rafiqul, it's incorrect. Why? Because we have only three items in the example discussed above. In your example, you are probably assuming that we have an infinite supply of items.
@rethink20s
@rethink20s 5 жыл бұрын
Great job bro
@ik_yola
@ik_yola 7 жыл бұрын
Poor explanation!
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Hi, Could you please tell us which part did you find hard to understand? Or, any suggestion on how we can improve?
@sudhansupradhan6891
@sudhansupradhan6891 7 жыл бұрын
nice one
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you, Sudhanshu! :)
@monikajha4239
@monikajha4239 6 жыл бұрын
good job!!!
@SUBRONEEL
@SUBRONEEL 7 жыл бұрын
sry but I had to say this .. compared to the other videos this video was really confusing..!
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thanks for the feedback. It is one of the earliest videos that we made. We have tried to keep the videos simpler from then on.
@SUBRONEEL
@SUBRONEEL 7 жыл бұрын
then can you please upload a video with simpler explanation on this problem. if possible :) keep up the good work.!
@KS-nc2ie
@KS-nc2ie 6 жыл бұрын
how can we know which set of items got selected?
4.5 0/1 Knapsack - Two Methods - Dynamic Programming
28:24
Abdul Bari
Рет қаралды 2,8 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 12 МЛН
Amazing Parenting Hacks! 👶✨ #ParentingTips #LifeHacks
00:18
Snack Chat
Рет қаралды 23 МЛН
Depth First Traversal for a Graph | GeeksforGeeks
6:25
GeeksforGeeks
Рет қаралды 479 М.
0/1 Knapsack problem | Dynamic Programming
13:29
WilliamFiset
Рет қаралды 156 М.
0-1 Knapsack Problem (Dynamic Programming)
9:20
CS Dojo
Рет қаралды 485 М.
01 Knapsack using Recursion | Building Intuition
18:38
Techdose
Рет қаралды 53 М.
Recitation 21: Dynamic Programming: Knapsack Problem
1:09:12
MIT OpenCourseWare
Рет қаралды 200 М.
Rod Cutting - Dynamic Programming
15:22
CSBreakdown
Рет қаралды 153 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1 МЛН
0/1 Knapsack Problem Dynamic Programming
15:50
Tushar Roy - Coding Made Simple
Рет қаралды 1,9 МЛН
3Blue1Brown's Probability Challenge Solved!
28:51
Mihai Nica
Рет қаралды 57 М.
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17