0% found this document useful (0 votes)
61 views18 pages

Session 8 - Greedy Method - Intro

This document introduces the greedy method algorithm. It discusses the components of a greedy algorithm including the candidate set, selection function, feasibility function, objective function, and solution function. An example is provided of using a greedy approach to maximize calories within a weight constraint when choosing between vegetable cakes. The greedy choice at each step is to select the cake with the highest utility value, defined as calories per unit weight. This leads to an optimal solution of choosing one 15g cake.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views18 pages

Session 8 - Greedy Method - Intro

This document introduces the greedy method algorithm. It discusses the components of a greedy algorithm including the candidate set, selection function, feasibility function, objective function, and solution function. An example is provided of using a greedy approach to maximize calories within a weight constraint when choosing between vegetable cakes. The greedy choice at each step is to select the cake with the highest utility value, defined as calories per unit weight. This leads to an optimal solution of choosing one 15g cake.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

19CS3113S

Introduction to Greedy Method

1
Insights

• Introduction to Greedy Method


• General example
• Components of Greedy Algorithm
• Control Abstraction of Greedy Algorithm
• Simple problems
Introduction

• These problems have N inputs and require us to obtain a subset


that satisfies some constraints.
• Any subset that satisfies those constraints is called a feasible
solution.
• Find the feasible solution that either maximizes or minimizes a
given objective function.
• A feasible solution that does this is called an optimal solution.
General Example: Vegetable Shop
Components of Greedy Algorithm
five components
• candidate set: solution is created from this set.
• selection function: Choose the best candidate.
• feasibility function: Check candidate can be used to contribute to
the solution.
• objective function: Assign a value to a solution or a partial
solution.
• solution function: Indicate whether a complete solution has been
reached.
Control Abstraction
Algorithm Greedy(A,N) {
// A[1:N] contains the N inputs.
solution:=0;// Initialize the solution.
for i :=1to n do {
x :=Select(a);
if feasible(solution, x) then
solution:=Union (solution, x);
}
return(solution);
}
Greedy Example
W=20 gm , E=30 cal W=10 gm, E=20 cal W=5 gm, E=15 cal

Max.Eat = 15 gm
Greedy Example

Feasible Solutions:
CAKE Profit
(15, 0, 0 ) 22.5
Greedy Example

Feasible Solutions:
CAKE Profit
(15, 0, 0 ) 22.5
( 5, 5, 5 ) 32.5
Greedy Example

Feasible Solutions:
CAKE Profit
(15, 0, 0 ) 22.5
( 5, 5, 5 ) 32.5
( 0, 10, 5 ) 35.0
Greedy Example

Feasible Solutions:
CAKE Profit
(15, 0, 0 ) 22.5
( 5, 5, 5 ) 32.5
( 0, 10, 5 ) 35.0
( 5, 10, 0) 27.5
Greedy Example
W=20 gm , E=30 cal W=10 gm, E=20 cal W=5 gm, E=15 cal
U.Val= 1.5 U.Val=2.0 U.Val=3.0

Max.Eat = 15 gm
Greedy Example
W=20 gm , E=30 cal W=10 gm, E=20 cal W=5 gm, E=15 cal
U.Val= 1.5 U.Val=2.0 U.Val=3.0

Max.Eat = 15 gm

W= 5, P=15
Greedy Example
W=20 gm , E=30 cal W=10 gm, E=20 cal W=5 gm, E=15 cal
U.Val= 1.5 U.Val=2.0 U.Val=3.0

Max.Eat = 15 gm

W= 15, P=35
Greedy Example

Feasible Solutions:
CAKE Cost
(15, 0, 0 ) 22.5
( 5, 5, 5 ) 32.5
( 0, 10, 5 ) 35.0
( 5, 10, 0) 27.5
Greedy Example
W=20 gm , E=30 cal W=10 gm, E=20 cal W=5 gm, E=15 cal
U.Val= 1.5 U.Val=2.0 U.Val=3.0

Max.Eat = 15 gm

Diabetic
Greedy Example
W=20 gm , E=30 cal W=10 gm, E=20 cal W=5 gm, E=15 cal
U.Val= 1.5 U.Val=2.0 U.Val=3.0

Max.Eat = 15 gm

W= 15, P=22.5
Thank You

You might also like