Greedy Method
PRESENTED BY
JUBAIDA QUADER JERIN
COMPUTER SCIENCE AND ENGINEERING (DEPT.)
9/23/2021 1
CREATED BY JUBAIDA QUADER JERIN
Topics
• Definition
• Problem Statement
• Real Life Example
• Algorithm
• Fail Condition
• Examples
9/23/2021 2
CREATED BY JUBAIDA QUADER JERIN
Greedy Method/ Algorithm
• Algorithmic approach
• Best optimal choice at each small stages
• From Local Optimal Leading to Global Optimal Choice
A Greedy Algorithm always makes the choice that looks best at the moment
9/23/2021 3
CREATED BY JUBAIDA QUADER JERIN
Problem: I have to go from A to B with minimum Cost and within 12 Hours.
P: A B
12 hours
Minimum cost
S: Walk Car Train Plane Boat ……..
Feasible Solution
Optimal Solution
1. Multiple Solutions: walk, car etc.
2. Two Feasible Solutions: Train and Boat
3. One Optimal Solution: Train
Hence, Greedy Method is applied Optimization Problems
9/23/2021 4
CREATED BY JUBAIDA QUADER JERIN
Real Life Example
Job Recruitment Process
80% 70% 40% 20% 1%
Call Online Screening Viva Final
Written
Selected Candidate
What method are they using?
Ans: Greedy Method
9/23/2021 5
CREATED BY JUBAIDA QUADER JERIN
Greedy Algorithm (A, n)
{
Solution <- 0
for i in range 1 to n do
{
s<- select (A)
if (Feasible (Solution, s)) then
Solution <- Union (Solution, s)
}
return Solution
}
* A is Domain from which solution is to be obtained of size n
9/23/2021 6
CREATED BY JUBAIDA QUADER JERIN
When Greedy Algorithm fails?
Example:
10 7 1
• 3 coins
• Sums up to 15
• Minimum Number of Coins Coin 1 Coin 2 Coin 3
Greedy Method: 1x 10 + 5x 1 = 6 coins
Correct Answer: 2x 7 + 1x 1 = 3 coins
Why Greedy Algorithm failed?
Local optimal doesn’t always result in Global Optimal
9/23/2021 7
CREATED BY JUBAIDA QUADER JERIN
Greedy Algorithm Example:
1. Job Sequenced with Deadline
2. Knapsack Problem
3. Huffman Coding
4. MST
5. Dijkstra Algorithm
9/23/2021 8
CREATED BY JUBAIDA QUADER JERIN
Thank You
9/23/2021 9
CREATED BY JUBAIDA QUADER JERIN

Greedy Algorithm by Jerin

  • 1.
    Greedy Method PRESENTED BY JUBAIDAQUADER JERIN COMPUTER SCIENCE AND ENGINEERING (DEPT.) 9/23/2021 1 CREATED BY JUBAIDA QUADER JERIN
  • 2.
    Topics • Definition • ProblemStatement • Real Life Example • Algorithm • Fail Condition • Examples 9/23/2021 2 CREATED BY JUBAIDA QUADER JERIN
  • 3.
    Greedy Method/ Algorithm •Algorithmic approach • Best optimal choice at each small stages • From Local Optimal Leading to Global Optimal Choice A Greedy Algorithm always makes the choice that looks best at the moment 9/23/2021 3 CREATED BY JUBAIDA QUADER JERIN
  • 4.
    Problem: I haveto go from A to B with minimum Cost and within 12 Hours. P: A B 12 hours Minimum cost S: Walk Car Train Plane Boat …….. Feasible Solution Optimal Solution 1. Multiple Solutions: walk, car etc. 2. Two Feasible Solutions: Train and Boat 3. One Optimal Solution: Train Hence, Greedy Method is applied Optimization Problems 9/23/2021 4 CREATED BY JUBAIDA QUADER JERIN
  • 5.
    Real Life Example JobRecruitment Process 80% 70% 40% 20% 1% Call Online Screening Viva Final Written Selected Candidate What method are they using? Ans: Greedy Method 9/23/2021 5 CREATED BY JUBAIDA QUADER JERIN
  • 6.
    Greedy Algorithm (A,n) { Solution <- 0 for i in range 1 to n do { s<- select (A) if (Feasible (Solution, s)) then Solution <- Union (Solution, s) } return Solution } * A is Domain from which solution is to be obtained of size n 9/23/2021 6 CREATED BY JUBAIDA QUADER JERIN
  • 7.
    When Greedy Algorithmfails? Example: 10 7 1 • 3 coins • Sums up to 15 • Minimum Number of Coins Coin 1 Coin 2 Coin 3 Greedy Method: 1x 10 + 5x 1 = 6 coins Correct Answer: 2x 7 + 1x 1 = 3 coins Why Greedy Algorithm failed? Local optimal doesn’t always result in Global Optimal 9/23/2021 7 CREATED BY JUBAIDA QUADER JERIN
  • 8.
    Greedy Algorithm Example: 1.Job Sequenced with Deadline 2. Knapsack Problem 3. Huffman Coding 4. MST 5. Dijkstra Algorithm 9/23/2021 8 CREATED BY JUBAIDA QUADER JERIN
  • 9.
    Thank You 9/23/2021 9 CREATEDBY JUBAIDA QUADER JERIN