0% found this document useful (0 votes)
34 views

0-1 Knapsack Problem (Greedy Algorithm)

The document discusses the greedy algorithm and its application to the 0-1 knapsack problem. It explains that a greedy algorithm works by making locally optimal choices at each step to arrive at a global optimum. This works when the problem exhibits the greedy choice property and optimal substructure. The document then provides examples of applications like Dijkstra's algorithm and Prim's/Kruskal's algorithm. It outlines the five components of greedy algorithms and notes pros like ease of finding solutions but cons like potential for non-optimal solutions in some cases. Finally, it defines the 0-1 knapsack problem as choosing to entirely accept or reject each item to maximize total value within a weight limit.

Uploaded by

Swati Rani
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

0-1 Knapsack Problem (Greedy Algorithm)

The document discusses the greedy algorithm and its application to the 0-1 knapsack problem. It explains that a greedy algorithm works by making locally optimal choices at each step to arrive at a global optimum. This works when the problem exhibits the greedy choice property and optimal substructure. The document then provides examples of applications like Dijkstra's algorithm and Prim's/Kruskal's algorithm. It outlines the five components of greedy algorithms and notes pros like ease of finding solutions but cons like potential for non-optimal solutions in some cases. Finally, it defines the 0-1 knapsack problem as choosing to entirely accept or reject each item to maximize total value within a weight limit.

Uploaded by

Swati Rani
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Amity University Jharkhand

Greedy Algorithm (0-1 Knapsack Problem)

Presented by : Presented to :
Muskaan Ms. Pooja Jha
Swati Rani
Introduction
 Greedy is an algorithmic paradigm that builds
up a solution piece by piece, always choosing
the next piece that offers the most obvious
and immediate benefit.
 So the problems where choosing locally
optimal also leads to global solution are best
fit for Greedy.
A Greedy algorithm works if a problem
exhibits the following two properties :

1. Greedy Choice Property


2. Optimal Substructure
Areas of Application
Greedy approach is used to solve many
problems , such as
 Finding the shortest path between two
vertices using Dijkstra’s algorithm
 Finding the minimal spanning tree in a graph
using Prim’s / Kruskal’s algorithm etc.
 Finding the maximum profit for the items to be
filled in a fixed weighted bag from Knapsack
algorithm
In general , Greedy algorithms have five
components :

1. A candidate set
2. A selection function
3. A feasibility function
4. An objective function
5. A solution function
Pros
 Finding solution is quite easy with Greedy algorithm
for a problem
 Analyzing the run time for Greedy algorithms will
generally be much easier than for other
techniques(like Divide and conquer)

Cons
 It is not suitable for problems where a solution is
required for every sub problem like sorting
 In such problems, the Greedy strategy can be wrong
; in worst case even lead to a non-optimal solution
0-1 Knapsack Problem

 The problem is called a “0-1” problem,


because each item must be entirely accepted
or rejected
 Example : finding the least wasteful way to
cut raw materials, selection of investments
and portfolios.
THANK
YOU

You might also like