Knapsack problem using greedy method

for i = 1 to ndo x[i] = 0weight = 0for i = 1 to nif weight + w[i] ≤ W thenx[i] = 1weight = weight + w[i]elsex[i] = (W — weight) / w[i]weight = Wbreakreturn x

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Decoupling (or Learning to Live With Code Redundancy)

Huawei Map Kit Integration

Airbyte or Meltano — and why I use neither of them

“It’s Not Safe If You’re A Trans Person”

K8s — kubectl

Hacknight 2.0, A Tale

Distributing a Messaging Queue

RISC-V simulation with Qemu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simran Malhotra

Simran Malhotra

More from Medium

Game of Life

Interview with David Cabello — Former GC for Compaq Computers

Delete only one occurrence of 5 from a number and return the maximum number

Recursion | A Picture is Worth 1,500 Words