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

КОМЕНТАРІ • 16

  • @golmatol6537
    @golmatol6537 4 місяці тому +4

    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.

    • @pitaeata8493
      @pitaeata8493 4 місяці тому

      i got lost on the last one too, still interesting.

  • @y2ksw1
    @y2ksw1 4 місяці тому +1

    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 😊

    • @rakotoarilantonirinadesire4110
      @rakotoarilantonirinadesire4110 3 місяці тому

      I think he has done it with the second solution. He was talking about ratio between value and weight.

    • @y2ksw1
      @y2ksw1 3 місяці тому

      @@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.

    • @Giovanni-rh1pw
      @Giovanni-rh1pw 2 місяці тому

      Your solution is "good enough" but doesn't return the actual best combination. There's no simple greedy solution to this problem.

    • @y2ksw1
      @y2ksw1 2 місяці тому

      @@Giovanni-rh1pw The industry wants the fastest and still best solution for the problem. In case of doubt, speed prevails.

  • @Dyanosis
    @Dyanosis 4 місяці тому

    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?

  • @MovieClips14359
    @MovieClips14359 4 місяці тому +2

    Build ai agent automation seo analyzer

  • @mrvincefox
    @mrvincefox 4 місяці тому

    Argh that damn keyboard.
    CLACK CLACK BASH BASH CLACK CLACK

  • @CodingDevelopers
    @CodingDevelopers 4 місяці тому

    Excellent video it helped me thx a lot. I am your fan so please pin me.

  • @coopernik
    @coopernik 4 місяці тому

    It’s just Tetris. Debate

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 4 місяці тому

    Broh, may I please know which software do you use to create your very good Thumbnails?

  • @philtoa334
    @philtoa334 4 місяці тому

    Thx_.