A pragmatic distillation of dynamic programming that prioritizes interview-ready procedures over deep algorithmic intuition. It is high-efficiency "fast food" for the mind, perfect for passing tests but insufficient for true mastery.
深掘り
前提条件
- データがありません。
次のステップ
- データがありません。
深掘り
0/1 Knapsack in 2 Minutes | All you need to know #knapsack #dsa #algorithms #daa #shorts #recap追加:
Hello everyone. Let's just have a quick recap about the 01 knapsack. Say you have a bag which can hold up to some limited capacity and have a lot of items in front of you. Each item having a some weight as well as some profit assigned to it.
Now, what is your target? Your target is to make sure you'll be picking those items up and be filling your bags in proper way so that your profit is maximized.
Now, unlike fractional knapsack, in case of 01 knapsack, you cannot pick a item fractionally. You need to either pick it or drop it. That's why it is known as 01 knapsack where zero stands for you're not picking that item and one stands for you're picking that item completely.
Now, which data structure does the 01 knapsack follows? This particular thing works on the data structure array. That is, there will be a weight array as well as the profit array.
And which kind of programming paradigm does it follow? This 01 knapsack follows the dynamic programming paradigm.
Now, if you see how does it work?
We need to create our DP table, that is dynamic programming table.
Where the column will be the maximum capacity of the bag, the rows will be each and every item, and each of the cell will be indicating the highest profit at that certain point.
Now, what are the things you need to do here? If you really look into it, whenever you see item, you have two options in your hand. You're either picking it or you're dropping it.
So, you need to fill that DP table accordingly.
If you're taking it, if you're picking it, in that case, you need to subtract the weight of that item from the remaining capacity of your bag. And for that, the profit will be added up. And if you're not taking it, if you see that that that particular element, if you pick it, it is not getting you more profit, then you simply ignore it. Then you simply copy the value from the previous cell or from the left hand side cell. So, you have two options, you need to pick the maximum [laughter] out of it. So, this is the formula for this one.
Now, if you want to see what is the time complexity of this one, you need to create a DP table and there what is the number of how many number of column and how many number of rows will be there, that is dependent upon the maximum capacity as well as the number of elements. So, the time complexity becomes order of n into w, where n is the number of elements and w is the highest capacity.
So, that is all about say that 0/1 knapsack and we have also discussed how it is different from the fractional knapsack.
Now, a dedicated complete video about this topic is already available in my top playlist. I am putting it up in the pinned comment. You can check it out.
Thank you for watching and stay tuned for the next videos.
関連おすすめ
resume fixed instantly 😭 Comment “app”andI’ll sendyou the link #parakeetaipartnership #resumetips
Ritcareer
686 views•2026-05-31
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
3D Basics in C
HirschDaniel
2K views•2026-06-05
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
Making Minecraft Clone with C++ & Raylib
PecaCSLive
686 views•2026-06-04
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











