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

--

--

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