# Write a program to implement knapsack problem using greedy method

What is the pseudocode for knapsack problem? Write a C Program to implement knapsack problem using greedy method knapsack definition: Consider we have given a set of items,each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.

It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.

The problem often arises in resource allocation where there are financial constraints and is studied in fields such as combinatorics, computer science, complexity theory, cryptography, applied mathematics, and daily fantasy sports.

The knapsack problem is interesting from the perspective of computer science for many reasons: The decision problem form of the knapsack problem is NP-complete, thus there is no known algorithms both correct and fast on all cases.

There is a pseudo-polynomial time algorithm using dynamic programming.

## How fast is it?

There is a fully polynomial-time approximation scheme, which uses the pseudo-polynomial time algorithm as a subroutine, 4. Many cases that arise in practice, and "random instances" from some distributions, can nonetheless be solved exactly.

A greedy algorithm is one that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum. In many problems, a greedy strategy does not in general produce an optimized solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time.program to implement knapsack problem using greedy method (1) program to implement quick sort (1) programme to find if the entered string is key word or not in c (1).

Here is source code of the C++ Program to Solve Knapsack Problem Using Dynamic Programming. The C++ program is successfully compiled and run on a Linux system.

The program output is .

## Important questions

Jul 05,  · program to implement knapsack problem using greedy method (1) program to implement quick sort (1) programme to find if the entered string is key word or not in c (1). For example, Fractional Knapsack problem can be solved using Greedy, but Knapsack cannot be solved using Greedy.

Following are some standard algorithms that are Greedy algorithms. 1) Kruskal`s Minuimum Spanning tree (MST): In Kruskal’s algorithm, we create a MST by picking edges one by one. problem is to find a layout that minimizes the total penalty. Prove or disprove that the following greedy algorithm correctly solves this problem for a and/or b. A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview .

Coin Change Problem | Algorithms