0% found this document useful (0 votes)
15 views43 pages

Knapsack

The document discusses the Knapsack Problem, highlighting its two types: the Fractional knapsack problem, which uses a greedy technique, and the 0/1 knapsack problem, which can be solved using dynamic programming. It explains the greedy algorithm, which makes locally optimal choices at each stage but may not always yield a globally optimal solution. The document also outlines the advantages and drawbacks of the greedy approach, emphasizing its simplicity and potential efficiency, while noting its limitations in producing optimal solutions.

Uploaded by

2020200000009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views43 pages

Knapsack

The document discusses the Knapsack Problem, highlighting its two types: the Fractional knapsack problem, which uses a greedy technique, and the 0/1 knapsack problem, which can be solved using dynamic programming. It explains the greedy algorithm, which makes locally optimal choices at each stage but may not always yield a globally optimal solution. The document also outlines the advantages and drawbacks of the greedy approach, emphasizing its simplicity and potential efficiency, while noting its limitations in producing optimal solutions.

Uploaded by

2020200000009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Knapsack Problem

Knapsack problem
• Types:
• Fractional knapsack problem
• 0/1 knapsack problem
• Fractional knapsack problem: Greedy technique
• 0/1 knapsack problem: Can be solved using Dynamic programming
Greedy Algorithm
• Follows the problem-solving heuristic of making the locally optimal choice
at each stage
• An approach for solving a problem by selecting the best option available at
the moment
• Doesn't worry whether the current best result will bring the overall optimal
result
• In many cases, a greedy strategy does not produce an optimal solution
• But a greedy heuristic can yield locally optimal solutions that approximate
a globally optimal solution in a reasonable amount of time
Greedy Algorithm
• Can be determined whether the algorithm can be used with any
problem if the problem has the following properties:
• Greedy Choice Property:
• If an optimal solution to the problem can be found by choosing the best choice at each
step
• Without reconsidering the previous steps once chosen, the problem can be solved using
a greedy approach
• Optimal Substructure:
• If the optimal overall solution to the problem corresponds to the optimal solution to its
subproblems
• Then the problem can be solved using a greedy approach
Advantages of Greedy Approach
• Easier to describe
• Can perform better than other algorithms (but, not in all cases)
Drawback of Greedy Approach
• Doesn't always produce the optimal solution
• Because it does not consider the entire data. The choice made by the
greedy approach does not consider future data and choices.

You might also like