Wrote logic for Knapsack Algorithm