GithubHelp home page GithubHelp logo

knapsack-problem's Introduction

Knapsack Problem

In this repo you can see three different Knapsack Problem solving methods(backtracking, branch and bound, brute force). You can find the source codes in the codes directory.

Run

You should run code of each solution separately. In each run you are asked to enter the following inputs:

  • Number of items in knapsack
  • Value and weight of each item
  • Capacity of knapsack

And the outputs you will see are:

  • Total time spent to run
  • Max Profit
  • Final selected itesms Inputs are read from the text file and also outputs are stored in the text file.

Comparison

  • Time: when the number of items is large, the backtracking method works better in terms of time and the program runs in less time, while the brute force method has the longest run time. If the weight of the knapsack and the number of items is low, the branch and bound method will be the fastest way to conclude.

  • Memory: all methods need 2n of memory to store the weights and values of the items. So, we compare the memory on the taken memory in calculating the max profit. If the knapsack capacity is less than 2, backtracking method with W * N memory, gets the least amount of memory, otherwise, the brute force method with 2 * n memory, gets the least memory. In the branch and bound method, in the worst case, 4 * 2 ^ (n - 1) + 2 ^ n space is needed to store the tree created in the queue, which is the highest amount of memory compared to the previous two methods.

knapsack-problem's People

Contributors

mobinamosannafat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.