Before watching this video, I was very confused about the dimension of DP , whether to take 2D / 3D , now I feel comfortable with it, I appreciate your efforts for this free and Top-Notch content !!!
bhaiiya jab aapne bola na left to right tb mere chehre pe ek smile thi or fir turant hi click kiya ki right to left se kuch nhi fatega. aapko sb pta hai kha kon bnda fas skta hai you are great teacher love you bhaiya 💖💖
I love the way u teach bhaiyaa still I have not watched this vedio due to my exams which starts from tomorrow but I can undoubtedly say it will be in next level I just came here to comment pls don't stop this dp series bhaiyaa I am literally depending on you once my exam completes I will resume watching your vedios bhaiyaa Lots of love from my side I am from Bangalore Karnataka
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exists on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂ Thanks you.
Ohhhhhhh bhaiyyyyaaa, one thing that I would like to tell you that I'm not sure that I will place in Product based company whether yes or not. But honestly I have been following your each & every video on UA-cam. So it will not matter that I will be placed or not but I'm sure that end of the knowledge I will make a character that will inspire to many students in upcoming time. Great thank you bhaiya!!. Just feel narvou or depressed 😔 nowadays!!
Thank You bhaiya !! I am solving all the questions you teach in your lecture and explain it my way and then upload the video on youtube! i want to try the teaching field as well. I even mailed you regarding your team (to be a part of your team.....hope you read it!)
At first... Thank You Very Much bhaiya.. cum sir! :) I don't know that if this much adventure was already present in this question how much I felt... But in this whole solution process by using all methods.... I enjoyed very much and learned a lot. During the whole hour... in every moment every point was clearly realized by your logic and describing. Thank you so much again sir
@@kushaalrana because for including W in the array we would need indexes from 0 to W and hence the required size of the array would be W+1, for n we don't have to use n+1 because the robber is carrying n items so an array of size n would do the job.
Bhaiya apse padh ke bahut hi achha laga dil se apko thanks bolna chahta hu Q ki ap ke teaching style ka to hm fan ho gye hai Bhaiya plz is course ko total complete kijiye ga bahut ummid hai is course se mere future ke liye Once again thank you bhaiya ❤️
highly recommended video for knapsack. best video i have ever seen, can be further more better if you show the optimization by putting the value in dp. but i understand its time issue. ❤
Thank you so much bhaiya... But, how can somebody think of starting the loop from w = weight[0] to maxWeight in analysing the first base case? Please somebody reply if have any logic from the front, or how it would click if asked impromptu?..
@@piyushgaur6975in initialisation, it is not weight[0]. It must be value[0]. J= 1 to W means we are checking weight from 1 to W. dp[0][w] show that when we have one element than what kind of profit we get. If weight of 1st element is less than bag weight than we have to take first element so that time we get the profit of first first element. Ex : bag cap = 10kg 1st element weight = 5kg Than dp[0][1] to dp[0][4] is zero And dp[0][5] to dp[0][6] is value[0].
In first loop why it start with w=weight[0] not w=0, i guess weight array is not given in sorted order. I tried using w=0 it's giving wrong answer. Can anyone explain please ??
@@kushaalrana For defining the size of dp array always look at how you are calling the solve recursive function for the first time from your main code. Since solve is called with solve(n - 1, maxCapacity) therefore we need to have size n and capacity + 1 to store all the results. It's no harm in creating a dp array with n+1 as well, but the nth position will never be used since the all the elements are from index 0 to n-1.
because -1 will never be an answer that will be computed for a subproblem so if array has -1 stored means this subproblems answer hasnt beeen computed and stored in array yet
some concepts which is not explained -> hameny dp initialization mai maxwieght kyu liya jabki ham index lete the , 2nd ->value aur capacity dono ki value change maar ri hia
Somebody please clear my doubt here!! In the solveTab method, in base case analysis why is the loop going from wt[0] to capacity ? Why not from 0 to capacity? Please help me understand this, anybody..
So here is the explanation- Here dp[i][j] will give you the value of the ith index with j weight, so now for the base case we are considering the 0th index only, which will have the wt[0] initially. Aise socho, hum uska weight increase kar rahe hai, aur hum tab tak increase kar sakte hai, jab tak vo capacity se jyada na ho jaaye.
In the tabular way, when analysing the base case (step 2), not sure why have we used "int w = weight[0]". Since we want to iterate from weight = 0 to weigth
sir yeh lecture ka explanation bilkul sahi nhi lga vector m n(row hai kaise ptaa) or maxweight(column hai yeh kaise ptaa chla) maxweight+1 he kyun kiya or tabulation for lopp condition base kaise hua or achese nhi smjhaya sir please explain to me
Bhai ye jo tum call back kr rhe the (recursion- 2d)tabulation mein samjhane ki bjae, uska link to at least daal dia kro. Kewal code dekhna hota to idhr kyu aata bro
Hello Bhaiya, I want to purchase your Comprehensive Data structure and algorithms course on unacedemy what should I do? Because in your course on unacedemy showing Enrollment close . I want to purchase your course please bhaiya ho ske to Enrollment on karvado na...
Before watching this video, I was very confused about the dimension of DP , whether to take 2D / 3D , now I feel comfortable with it, I appreciate your efforts for this free and Top-Notch content !!!
The demagorgan of dsa no one can kill!! You are amazing!!
The fear of dp is rapidly decreasing due to such great videos
Thanks a lot and lot bhaiya
Feeling lucky to have your videos for my preparation
Questions:
1. 0/1 Knapsack
2. Equal Subset Sum Partition
3. Subset Sum
4. Minimum subset sum difference
5. Count of subset sum
6. Target Sum
Never seen such simple and more descriptive way to understand such a complex problem, Such DP videos are just awesome :)
bhaiiya jab aapne bola na left to right tb mere chehre pe ek smile thi or fir turant hi click kiya ki right to left se kuch nhi fatega. aapko sb pta hai kha kon bnda fas skta hai you are great teacher love you bhaiya 💖💖
I love the way u teach bhaiyaa still I have not watched this vedio due to my exams which starts from tomorrow but I can undoubtedly say it will be in next level I just came here to comment pls don't stop this dp series bhaiyaa I am literally depending on you once my exam completes I will resume watching your vedios bhaiyaa
Lots of love from my side
I am from Bangalore Karnataka
Address bhi de dete apna
Stop this bhaiya culture
Happy Teacher's Day Bhaiya.Grateful for everything you have done for us.May Krishna bless you profusely.🙏🙏
Just needed DP. Thank you 💕
❤
consistency ++ ! and yes consistency is Underated!
❤❤ DP looks simpler now , Lecture Completed... Keep going bhaiya👏👏
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exists on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂ Thanks you.
bhai tu bada khali aadmi hai yar
Ohhhhhhh bhaiyyyyaaa, one thing that I would like to tell you that I'm not sure that I will place in Product based company whether yes or not. But honestly I have been following your each & every video on UA-cam. So it will not matter that I will be placed or not but I'm sure that end of the knowledge I will make a character that will inspire to many students in upcoming time. Great thank you bhaiya!!. Just feel narvou or depressed 😔 nowadays!!
That's really true
Main bhi BCA krrha hu lkin kuch sure nhi h kya hoga
1 saal ho gaya ye comment ko... placement hui bhai ?
@@CGhitaarth 🤣🤣
I hope you are placed bro
bina bahut jada coding jane bhi agar aapki video se pahdo to bhayia pura pura samjh ata h.
Thank You bhaiya !! I am solving all the questions you teach in your lecture and explain it my way and then upload the video on youtube! i want to try the teaching field as well. I even mailed you regarding your team (to be a part of your team.....hope you read it!)
This is by far the best Knapsack video I've ever seen...
Last approach dekh kar toh maza hi aa gya bhaiya , thanks a lot !!!
At first... Thank You Very Much bhaiya.. cum sir! :)
I don't know that if this much adventure was already present in this question how much I felt... But in this whole solution process by using all methods.... I enjoyed very much and learned a lot. During the whole hour... in every moment every point was clearly realized by your logic and describing. Thank you so much again sir
w = weight[0] kyu lagaya usi pe toh atka hun 28:40
It actually doesn't matter if you start it with w=0 or w=weight[0], if you look at next if condition then....all values from w=0 till w
@@UtkarshSinha-ok5fg one more question why did 2d dp have n, w+1, why not n+1 and w+1
@@kushaalrana because for including W in the array we would need indexes from 0 to W and hence the required size of the array would be W+1,
for n we don't have to use n+1 because the robber is carrying n items so an array of size n would do the job.
sir ji late cahl raha hu dheere dheere pahuchunga isme !! just bata raha hu ki aapka kaam best h !!!
Bhaiya apse padh ke bahut hi achha laga dil se apko thanks bolna chahta hu Q ki ap ke teaching style ka to hm fan ho gye hai
Bhaiya plz is course ko total complete kijiye ga bahut ummid hai is course se mere future ke liye
Once again thank you bhaiya ❤️
highly recommended video for knapsack. best video i have ever seen, can be further more better if you show the optimization by putting the value in dp.
but i understand its time issue. ❤
Great explanation. Glad that you covered all the scenarios which gives crystal clear clarity for the given problem statement.
i didn't understatand the last 2 videos but this one amazing cleared all the doubts
Loving the series ❤️❤️❤️❤️❤️❤️❤️❤️
Bhaiya, why have you returned prev[capacity] and why not curr[capacity]? n-1 denotes the last row right, which is curr.
Thank you so much bhaiya...
But, how can somebody think of starting the loop from w = weight[0] to maxWeight in analysing the first base case?
Please somebody reply if have any logic from the front, or how it would click if asked impromptu?..
Thanku
Explained the concept in a very easy way.
Just amazing lecture 🎉😊
Babbar bhaiya!!
Thank You So Much BHRATA SHREE !!!!!!!
I am having problem where you write the code of =>analyse the base case in solveTab( )
Why you run for loop from weight [0] to capacity
You can write like below also -
//for all index 0 and weight from 1 to max weight we need to take care
for(int i = 1; i
Bhaiya c++ DSA me leetcode par qus solve nhi ho rhe hai 😭
Don't worry, just keep trying & practicing!!
Ab ho raha hai kya ?
@@technoakshay20 ab uski placement lg gyi bhai
It would have been better if how the 2D array got filled had been shown; otherwise, great explanation!
Nice, thnks for teaching different approaches ❤
Thank You for this amazing lecture
Bhai Gajab ka explain Kiya hai. Maja aa gaya.
bhai mujhe smjh nhi aaya yaar Bottom Aproach mein DP intialization smjh
for(int j = 1; j
@@piyushgaur6975in initialisation, it is not weight[0]. It must be value[0].
J= 1 to W means we are checking weight from 1 to W. dp[0][w] show that when we have one element than what kind of profit we get. If weight of 1st element is less than bag weight than we have to take first element so that time we get the profit of first first element.
Ex : bag cap = 10kg
1st element weight = 5kg
Than
dp[0][1] to dp[0][4] is zero
And dp[0][5] to dp[0][6] is value[0].
@@vaishnavrushikesh4022 arey bhai thank you very much bhaii, mein bta nhi skta kitna pareshaan hogya tha m ...smjh hi nhi aara tha thanks
One thing I have to say that, In the initialization loop of bottom up approach
for(int j = weight[0]; j
@@piyushgaur6975 correct but note one thing when you make dp vector thay you have to initialise all the elements to 0.
138 ✅completed 👍Liked 12:07
last solution was fab💥
In first loop why it start with w=weight[0] not w=0, i guess weight array is not given in sorted order. I tried using w=0 it's giving wrong answer. Can anyone explain please ??
no, bro. you can actually start with w = 0. only change is instead of checking if weight[0]
@@shashwatkumar6965 can you also clarify why is dp array starting from n,capcity+1 and why not from n+1, capacity+1
@@kushaalrana For defining the size of dp array always look at how you are calling the solve recursive function for the first time from your main code. Since solve is called with solve(n - 1, maxCapacity) therefore we need to have size n and capacity + 1 to store all the results. It's no harm in creating a dp array with n+1 as well, but the nth position will never be used since the all the elements are from index 0 to n-1.
@@shashwatkumar6965 Thank you so much❤️, that was very precise 🔥💯
Bhaiya poori playlist kab tk bnegi ...ye Last video hai ya aur aage kitne months mai complete hoga course
Bhai pls make programs in java also.......💯pls bhai, it'll be helpful for more JAVA people including me 🙂
Bhaiya last wala line mast the left to right😂😂
you are such a great great bhaiya we all are love you bhaiya so much
Why do we initialize dp array with -1 while top-down approach (Memoization) and with 0 while bottom-up (tabulation)?
you can do anything
because -1 will never be an answer that will be computed for a subproblem
so if array has -1 stored means this subproblems answer hasnt beeen computed and stored in array yet
meanwhile in bottom up, vectors automatically initialize with 0 so you dont need to explicitly initialize with 0
How can I pay my gurudakshina?
Thank you. But did you guys not find it overwhelming? So many concepts to grasp.
some concepts which is not explained -> hameny dp initialization mai maxwieght kyu liya jabki ham index lete the , 2nd ->value aur capacity dono ki value change maar ri hia
Explain how to write for loop in base cases
Is there any benefit of memoization in knapsack problem as there is no overlapping sub problem in dry run.
🔥🔥first comment
First like 👍👍
bhiya prev = curr and curr = new int[capacity+1]
Bro for greedy, graphs etc also we need roadmap similar to dp
Somebody please clear my doubt here!!
In the solveTab method, in base case analysis
why is the loop going from wt[0] to capacity ? Why not from 0 to capacity?
Please help me understand this, anybody..
@CodeHelp - by Babbar
So here is the explanation-
Here dp[i][j] will give you the value of the ith index with j weight, so now for the base case we are considering the 0th index only, which will have the wt[0] initially.
Aise socho, hum uska weight increase kar rahe hai, aur hum tab tak increase kar sakte hai, jab tak vo capacity se jyada na ho jaaye.
Kya ho if weight[0] is greater than capacity?
Bhayankar 🎉🔥
charging karte hue kya camera record nahi karta kya , ya in camera's ki battery alaga se nikal ke change hoti hai??
dil garden garden ho gya ! 😃 Thanks alot bhaiya !
sir, in some memo Q you start index from 0 and base case at n-1, in others from n-1 and base case at 0. Why this confusion? Can someone clear!!
Superb bro
Best Best DSA course on UA-cam.
In the tabular way, when analysing the base case (step 2), not sure why have we used "int w = weight[0]". Since we want to iterate from weight = 0 to weigth
in this case rows[0] all cols value will set as 0 means this weight can't fit on this bag
Brilliant Content
Can we implement recursive approach left to right and make the base case if(index ==n-1){....}. If not can anyone please explain why?
YES we can do in that way also
gfg ans :
int solve(int w, int i, int wt[], int val[],int n, vector&dp){
if(i==n-1){
if(wt[i]
consistency++
Present Bhaiya
Jabse dp aur graph shuru hue hai tabse samajh aana kam ho gya bhaiya
Sir plz 40 lecture ke baad ka note upload kar dijiye
tough lagra bhaiya🥲
sir yeh lecture ka explanation bilkul sahi nhi lga vector m n(row hai kaise ptaa) or maxweight(column hai yeh kaise ptaa chla) maxweight+1 he kyun kiya or tabulation for lopp condition base kaise hua or achese nhi smjhaya sir please explain to me
Thoda samaj aaya 😅😅😅
atleast one dry run would help everyone to grasp the knowledge quickly.
best
Bhaiya ab thoda confidence aa raha hai shayad kahi ache jagah lag jau.Thankyou bhaiya for this amazing content.
bhai mujhe smjh nhi aaya yaar Bottom Aproach mein DP intialization smjh
for(int j = 1; j
❤️🤞 thank you bhaiya
why are we initializing include=0 and exclude=0 everytimme we call the function.
Bottom up approach bohot fast hogayi, smj hi nahi aaya kya ho rha h :(, if anyone could make me understand what's happening, it would be helpful
Took time but understood by self exploring various solutions
Good content but lack of explanation why what happened especially tabulation
Last wala optimization bilkul samajh nahi aya
7:50 brute force
Bhai ye jo tum call back kr rhe the (recursion- 2d)tabulation mein samjhane ki bjae, uska link to at least daal dia kro. Kewal code dekhna hota to idhr kyu aata bro
Thank you bhaiya , attendance done
Just Awesome!!!
Thanks for vedio sukhjit here
Now the video length is op
Hello Bhaiya,
I want to purchase your Comprehensive Data structure and algorithms course on unacedemy what should I do? Because in your course on unacedemy showing Enrollment close . I want to purchase your course please bhaiya ho ske to Enrollment on karvado na...
Bhaiya abbb Continue Videos aayegi na 😃😃🔥
Haa bhai aaye gi
Can anyone just tell me why we have initialized dp array with 0 in tabulation method ?
mt kro fir bhi chlega
vectors automatically initialize with 0
Great timing Love Bhaiya... Thanks
Nice video 😇😇😇
Maja aa raha hai
Yeahhh 🔥🔥🔥.... Do you need any Web Development Intern... I will be really glad
can someone explain why does he not get negative index error
becoz 0 doesn't have any effect on final answer but -1 will affect answer
Bhaiya mujhe only java language aati h , cpp ni aati.... Dp series kaise start kru ?
implement in java
21:29 32:39
hash last smjhaa
Love babbar sir you are best 🔥🔥❣️
bhaiya aapne jaise notes suru main dale the vese notes aapne sari videos ke bna ke kyun nhi daale please bhiya daal do isse hm log ko bahut help mlegi
anothe rway to solve this easily 😉
static int solve(int w, int wt[], int val[], int i){
int sum = 0, max = 0;
for(int j=i;j
very good explanation about knapsack problem
✔✔✔✔
why we have initialized w by weight[0]..??? Can anyone explain