Knapsack Problem Explained - Algorithms in Python
Вставка
- Опубліковано 27 вер 2024
- Today we learn about the Knapsack Problem. We implement three different algorithms to solve it in Python and we analyze their complexity.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine...
💻 The Algorithm Bible Book: www.neuralnine...
👕 Programming Merch: www.neuralnine...
💼 Services 💼
💻 Freelancing & Tutoring: www.neuralnine...
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine...
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/Neu...
🎙 Discord: / discord
Wish you had drawn out an actual table (perhaps with just 3-4 items) and run through it manually to show the values are being updated. Will need to watch some other knapsack related video now to really understand that last algorithm.
i got lost on the last one too, still interesting.
It's actually pretty easy to solve: search for the item with the largest value and smallest weight. Then repeat until the sack is filled.
This is the method I have used at industrial scale and it performs outstandingly. Performance is the highest value in the industry, because time is money 😊
I think he has done it with the second solution. He was talking about ratio between value and weight.
@@rakotoarilantonirinadesire4110 He computed a value and ordered it accordingly to it. However, on large data fields, division is more expensive than multiplication, and sorting prohibitive, if not impossible. Imagine a large user database and the intent to collect a number of members with similar attributes. With my method, I do a record scan and remember simply the records, in a small array, which match the criteria, over the whole set of records. By the time I would make the division or multiplication, I have the values already placed, and by the time the second iteration of a sorting algorithm would start, I have scanned all data.
Your solution is "good enough" but doesn't return the actual best combination. There's no simple greedy solution to this problem.
@@Giovanni-rh1pw The industry wants the fastest and still best solution for the problem. In case of doubt, speed prevails.
Your dynamic algo is definitely not efficient if you're looping over i and w and not just starting from 1 instead of 0. Why start from a number and be forced to initialized and ignore it if you could start from a number that matters? Also, seems a little weird that you're loops from 0 to 15 but looking at the previous item and previous DP. Wouldn't it make just as much sense to loop from 0 to 14 and get the same result?
Build ai agent automation seo analyzer
good idea
Argh that damn keyboard.
CLACK CLACK BASH BASH CLACK CLACK
Excellent video it helped me thx a lot. I am your fan so please pin me.
It’s just Tetris. Debate
Broh, may I please know which software do you use to create your very good Thumbnails?
Thx_.