Skip to content

Instantly share code, notes, and snippets.

View elfekym's full-sized avatar

Mohamed El-Feky elfekym

View GitHub Profile
@elfekym
elfekym / knapsack.js
Created March 12, 2018 08:32 — forked from danwoods/knapsack.js
Knapsack algorithm in JavaScript
//Knapsack algorithm
//==================
// wikipedia: [Knapsack (0/1)](http://en.wikipedia.org/wiki/Knapsack_problem#0.2F1_Knapsack_Problem)
// Given a set `[{weight:Number, benefit:Number}]` and a capacity,
// find the maximum value possible while keeping the weight below
// or equal to the capacity
// **params**:
// `capacity` : Number,
// `items` : [{w:Number, b:Number}]
// **returns**: