SlideShare a Scribd company logo
8
Most read
9
Most read
10
Most read
The Greedy Method 1
The Greedy Method
The Greedy Method 2
Outline and Reading
The Greedy Method Technique (§5.1)
Fractional Knapsack Problem (§5.1.1)
Task Scheduling (§5.1.2)
Minimum Spanning Trees (§7.3) [future lecture]
The Greedy Method 3
The Greedy Method
Technique
The greedy method is a general algorithm
design paradigm, built on the following
elements:
 configurations: different choices, collections, or
values to find
 objective function: a score assigned to
configurations, which we want to either maximize or
minimize
It works best when applied to problems with the
greedy-choice property:
 a globally-optimal solution can always be found by a
series of local improvements from a starting
configuration.
The Greedy Method 4
Making Change
Problem: A dollar amount to reach and a collection of
coin amounts to use to get there.
Configuration: A dollar amount yet to return to a
customer plus the coins already returned
Objective function: Minimize number of coins returned.
Greedy solution: Always return the largest coin you can
Example 1: Coins are valued $.32, $.08, $.01
 Has the greedy-choice property, since no amount over $.32 can
be made with a minimum number of coins by omitting a $.32
coin (similarly for amounts over $.08, but under $.32).
Example 2: Coins are valued $.30, $.20, $.05, $.01
 Does not have greedy-choice property, since $.40 is best made
with two $.20’s, but the greedy solution will pick three coins
(which ones?)
The Greedy Method 5
The Fractional Knapsack
Problem
Given: A set S of n items, with each item i having
 bi - a positive benefit
 wi - a positive weight
Goal: Choose items with maximum total benefit but with
weight at most W.
If we are allowed to take fractional amounts, then this is
the fractional knapsack problem.
 In this case, we let xi denote the amount we take of item i
 Objective: maximize
 Constraint:

S
i
i
i
i w
x
b )
/
(



S
i
i W
x
The Greedy Method 6
Example
Given: A set S of n items, with each item i having
 bi - a positive benefit
 wi - a positive weight
Goal: Choose items with maximum total benefit but with
weight at most W.
Weight:
Benefit:
1 2 3 4 5
4 ml 8 ml 2 ml 6 ml 1 ml
$12 $32 $40 $30 $50
Items:
Value: 3
($ per ml)
4 20 5 50
10 ml
Solution:
• 1 ml of 5
• 2 ml of 3
• 6 ml of 4
• 1 ml of 2
“knapsack”
The Greedy Method 7
The Fractional Knapsack
Algorithm
Greedy choice: Keep taking
item with highest value
(benefit to weight ratio)
 Since
 Run time: O(n log n). Why?
Correctness: Suppose there
is a better solution
 there is an item i with higher
value than a chosen item j,
but xi<wi, xj>0 and vi<vj
 If we substitute some i with j,
we get a better solution
 How much of i: min{wi-xi, xj}
 Thus, there is no better
solution than the greedy one
Algorithm fractionalKnapsack(S, W)
Input: set S of items w/ benefit bi
and weight wi; max. weight W
Output: amount xi of each item i
to maximize benefit w/ weight
at most W
for each item i in S
xi  0
vi  bi / wi {value}
w  0 {total weight}
while w < W
remove item i w/ highest vi
xi  min{wi , W - w}
w  w + min{wi , W - w}

 


S
i
i
i
i
S
i
i
i
i x
w
b
w
x
b )
/
(
)
/
(
The Greedy Method 8
Task Scheduling
Given: a set T of n tasks, each having:
 A start time, si
 A finish time, fi (where si < fi)
Goal: Perform all the tasks using a minimum number of
“machines.”
1 9
8
7
6
5
4
3
2
Machine 1
Machine 3
Machine 2
The Greedy Method 9
Task Scheduling
Algorithm
Greedy choice: consider tasks
by their start time and use as
few machines as possible with
this order.
 Run time: O(n log n). Why?
Correctness: Suppose there is a
better schedule.
 We can use k-1 machines
 The algorithm uses k
 Let i be first task scheduled
on machine k
 Machine i must conflict with
k-1 other tasks
 But that means there is no
non-conflicting schedule
using k-1 machines
Algorithm taskSchedule(T)
Input: set T of tasks w/ start time si
and finish time fi
Output: non-conflicting schedule
with minimum number of machines
m  0 {no. of machines}
while T is not empty
remove task i w/ smallest si
if there’s a machine j for i then
schedule i on machine j
else
m  m + 1
schedule i on machine m
The Greedy Method 10
Example
Given: a set T of n tasks, each having:
 A start time, si
 A finish time, fi (where si < fi)
 [1,4], [1,3], [2,5], [3,7], [4,7], [6,9], [7,8] (ordered by start)
Goal: Perform all tasks on min. number of machines
1 9
8
7
6
5
4
3
2
Machine 1
Machine 3
Machine 2

More Related Content

What's hot (20)

PPTX
Traveling salesman problem
Jayesh Chauhan
 
PPT
Greedy algorithms
Rajendran
 
PPTX
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
PPTX
Knapsack problem using greedy approach
padmeshagrekar
 
PPTX
Divide and Conquer - Part 1
Amrinder Arora
 
PDF
Introduction to Recurrent Neural Network
Knoldus Inc.
 
PPTX
Asymptotic Notation and Data Structures
Amrinder Arora
 
PPTX
N queens using backtracking
srilekhagourishetty
 
PDF
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
DOC
Unit 2 in daa
Nv Thejaswini
 
PPTX
Support Vector Machine ppt presentation
AyanaRukasar
 
PDF
I. AO* SEARCH ALGORITHM
vikas dhakane
 
PPTX
NLP_KASHK:N-Grams
Hemantha Kulathilake
 
PDF
Practical Non-Monotonic Reasoning
Guido Governatori
 
PPT
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
PPT
Branch and bound
Dr Shashikant Athawale
 
PPT
Backtracking Algorithm.ppt
SalmIbrahimIlyas
 
PPTX
Decision tree induction \ Decision Tree Algorithm with Example| Data science
MaryamRehman6
 
PPTX
Backtracking
subhradeep mitra
 
Traveling salesman problem
Jayesh Chauhan
 
Greedy algorithms
Rajendran
 
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Knapsack problem using greedy approach
padmeshagrekar
 
Divide and Conquer - Part 1
Amrinder Arora
 
Introduction to Recurrent Neural Network
Knoldus Inc.
 
Asymptotic Notation and Data Structures
Amrinder Arora
 
N queens using backtracking
srilekhagourishetty
 
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Unit 2 in daa
Nv Thejaswini
 
Support Vector Machine ppt presentation
AyanaRukasar
 
I. AO* SEARCH ALGORITHM
vikas dhakane
 
NLP_KASHK:N-Grams
Hemantha Kulathilake
 
Practical Non-Monotonic Reasoning
Guido Governatori
 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Branch and bound
Dr Shashikant Athawale
 
Backtracking Algorithm.ppt
SalmIbrahimIlyas
 
Decision tree induction \ Decision Tree Algorithm with Example| Data science
MaryamRehman6
 
Backtracking
subhradeep mitra
 

Similar to Greedy with Task Scheduling Algorithm.ppt (20)

PPT
Greedy
koralverma
 
PPT
Greedy method1
Rajendran
 
PDF
greedy method.pdf
deepakjoshi29912
 
PPT
Greedy method by Dr. B. J. Mohite
Zeal Education Society, Pune
 
PDF
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
MAJDABDALLAH3
 
PPTX
daa-unit-3-greedy method
hodcsencet
 
PPTX
Module 3_DAA (2).pptx
AnkitaVerma776806
 
PDF
Unit 3 - Greedy Method
MaryJacob24
 
PDF
Unit 3 greedy method
MaryJacob24
 
PDF
12 Greeddy Method
Andres Mendez-Vazquez
 
PPTX
ppt 2.pptxlmkgngxjgdjgdjtxjgxjgxnvndjcgxjxjjc
ArunavaGhosh36
 
PPTX
Unit 3- Greedy Method.pptx
MaryJacob24
 
PPTX
Greedy method class 11
Kumar
 
PPTX
Greedy Method unit-2(Design and analysis of algorithms).pptx
shivani366010
 
PPT
Lec30
Nikhil Chilwant
 
PPT
Unit 3-Greedy Method
DevaKumari Vijay
 
PDF
Module 2 - Greedy Algorithm Data structures and algorithm
farzanirani201402
 
PPTX
Greedy-Algorithms with Applications.pptx
Riannel Tecson
 
PDF
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
22bcs058
 
PDF
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
 
Greedy
koralverma
 
Greedy method1
Rajendran
 
greedy method.pdf
deepakjoshi29912
 
Greedy method by Dr. B. J. Mohite
Zeal Education Society, Pune
 
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
MAJDABDALLAH3
 
daa-unit-3-greedy method
hodcsencet
 
Module 3_DAA (2).pptx
AnkitaVerma776806
 
Unit 3 - Greedy Method
MaryJacob24
 
Unit 3 greedy method
MaryJacob24
 
12 Greeddy Method
Andres Mendez-Vazquez
 
ppt 2.pptxlmkgngxjgdjgdjtxjgxjgxnvndjcgxjxjjc
ArunavaGhosh36
 
Unit 3- Greedy Method.pptx
MaryJacob24
 
Greedy method class 11
Kumar
 
Greedy Method unit-2(Design and analysis of algorithms).pptx
shivani366010
 
Unit 3-Greedy Method
DevaKumari Vijay
 
Module 2 - Greedy Algorithm Data structures and algorithm
farzanirani201402
 
Greedy-Algorithms with Applications.pptx
Riannel Tecson
 
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
22bcs058
 
Unit-3 greedy method, Prim's algorithm, Kruskal's algorithm.pdf
yashodamb
 
Ad

More from Ruchika Sinha (20)

PPT
Python Programming Introduction - Loops & Boolean
Ruchika Sinha
 
PPTX
Difference Between Normal & Smart/Automated Home
Ruchika Sinha
 
PPT
Greedy Algorithms WITH Activity Selection Problem.ppt
Ruchika Sinha
 
PPT
Greedy with Task Scheduling Algorithm.ppt
Ruchika Sinha
 
PPT
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
PPT
DynProg_Knapsack.ppt
Ruchika Sinha
 
PPT
Dijkstra.ppt
Ruchika Sinha
 
PPT
Clipping
Ruchika Sinha
 
PPT
Lec22 intel
Ruchika Sinha
 
PPTX
Pc assembly
Ruchika Sinha
 
PPT
Casing
Ruchika Sinha
 
PPTX
Installation of motherboard
Ruchika Sinha
 
PPT
Shortest path
Ruchika Sinha
 
PPT
Bellman ford algorithm
Ruchika Sinha
 
PPTX
Python material
Ruchika Sinha
 
PPT
Python3
Ruchika Sinha
 
PPT
Optimization problems
Ruchika Sinha
 
PPT
Regular Grammar
Ruchika Sinha
 
PPTX
Software Teting
Ruchika Sinha
 
PPTX
Backtrack search-algorithm
Ruchika Sinha
 
Python Programming Introduction - Loops & Boolean
Ruchika Sinha
 
Difference Between Normal & Smart/Automated Home
Ruchika Sinha
 
Greedy Algorithms WITH Activity Selection Problem.ppt
Ruchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Ruchika Sinha
 
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
DynProg_Knapsack.ppt
Ruchika Sinha
 
Dijkstra.ppt
Ruchika Sinha
 
Clipping
Ruchika Sinha
 
Lec22 intel
Ruchika Sinha
 
Pc assembly
Ruchika Sinha
 
Installation of motherboard
Ruchika Sinha
 
Shortest path
Ruchika Sinha
 
Bellman ford algorithm
Ruchika Sinha
 
Python material
Ruchika Sinha
 
Python3
Ruchika Sinha
 
Optimization problems
Ruchika Sinha
 
Regular Grammar
Ruchika Sinha
 
Software Teting
Ruchika Sinha
 
Backtrack search-algorithm
Ruchika Sinha
 
Ad

Recently uploaded (20)

PPTX
Work at Height training for workers .pptx
cecos12
 
PDF
Plant Control_EST_85520-01_en_AllChanges_20220127.pdf
DarshanaChathuranga4
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
PDF
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
PDF
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
 
PDF
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PDF
June 2025 - Top 10 Read Articles in Network Security and Its Applications
IJNSA Journal
 
PDF
01-introduction to the ProcessDesign.pdf
StiveBrack
 
PDF
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
PDF
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
PDF
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
PDF
Bayesian Learning - Naive Bayes Algorithm
Sharmila Chidaravalli
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PDF
bs-en-12390-3 testing hardened concrete.pdf
ADVANCEDCONSTRUCTION
 
PDF
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
 
PDF
PRIZ Academy - Process functional modelling
PRIZ Guru
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
PPTX
Explore USA’s Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
 
Work at Height training for workers .pptx
cecos12
 
Plant Control_EST_85520-01_en_AllChanges_20220127.pdf
DarshanaChathuranga4
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
 
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
June 2025 - Top 10 Read Articles in Network Security and Its Applications
IJNSA Journal
 
01-introduction to the ProcessDesign.pdf
StiveBrack
 
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
Bayesian Learning - Naive Bayes Algorithm
Sharmila Chidaravalli
 
Functions in Python Programming Language
BeulahS2
 
bs-en-12390-3 testing hardened concrete.pdf
ADVANCEDCONSTRUCTION
 
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
 
PRIZ Academy - Process functional modelling
PRIZ Guru
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
Explore USA’s Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
 

Greedy with Task Scheduling Algorithm.ppt

  • 1. The Greedy Method 1 The Greedy Method
  • 2. The Greedy Method 2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1) Task Scheduling (§5.1.2) Minimum Spanning Trees (§7.3) [future lecture]
  • 3. The Greedy Method 3 The Greedy Method Technique The greedy method is a general algorithm design paradigm, built on the following elements:  configurations: different choices, collections, or values to find  objective function: a score assigned to configurations, which we want to either maximize or minimize It works best when applied to problems with the greedy-choice property:  a globally-optimal solution can always be found by a series of local improvements from a starting configuration.
  • 4. The Greedy Method 4 Making Change Problem: A dollar amount to reach and a collection of coin amounts to use to get there. Configuration: A dollar amount yet to return to a customer plus the coins already returned Objective function: Minimize number of coins returned. Greedy solution: Always return the largest coin you can Example 1: Coins are valued $.32, $.08, $.01  Has the greedy-choice property, since no amount over $.32 can be made with a minimum number of coins by omitting a $.32 coin (similarly for amounts over $.08, but under $.32). Example 2: Coins are valued $.30, $.20, $.05, $.01  Does not have greedy-choice property, since $.40 is best made with two $.20’s, but the greedy solution will pick three coins (which ones?)
  • 5. The Greedy Method 5 The Fractional Knapsack Problem Given: A set S of n items, with each item i having  bi - a positive benefit  wi - a positive weight Goal: Choose items with maximum total benefit but with weight at most W. If we are allowed to take fractional amounts, then this is the fractional knapsack problem.  In this case, we let xi denote the amount we take of item i  Objective: maximize  Constraint:  S i i i i w x b ) / (    S i i W x
  • 6. The Greedy Method 6 Example Given: A set S of n items, with each item i having  bi - a positive benefit  wi - a positive weight Goal: Choose items with maximum total benefit but with weight at most W. Weight: Benefit: 1 2 3 4 5 4 ml 8 ml 2 ml 6 ml 1 ml $12 $32 $40 $30 $50 Items: Value: 3 ($ per ml) 4 20 5 50 10 ml Solution: • 1 ml of 5 • 2 ml of 3 • 6 ml of 4 • 1 ml of 2 “knapsack”
  • 7. The Greedy Method 7 The Fractional Knapsack Algorithm Greedy choice: Keep taking item with highest value (benefit to weight ratio)  Since  Run time: O(n log n). Why? Correctness: Suppose there is a better solution  there is an item i with higher value than a chosen item j, but xi<wi, xj>0 and vi<vj  If we substitute some i with j, we get a better solution  How much of i: min{wi-xi, xj}  Thus, there is no better solution than the greedy one Algorithm fractionalKnapsack(S, W) Input: set S of items w/ benefit bi and weight wi; max. weight W Output: amount xi of each item i to maximize benefit w/ weight at most W for each item i in S xi  0 vi  bi / wi {value} w  0 {total weight} while w < W remove item i w/ highest vi xi  min{wi , W - w} w  w + min{wi , W - w}      S i i i i S i i i i x w b w x b ) / ( ) / (
  • 8. The Greedy Method 8 Task Scheduling Given: a set T of n tasks, each having:  A start time, si  A finish time, fi (where si < fi) Goal: Perform all the tasks using a minimum number of “machines.” 1 9 8 7 6 5 4 3 2 Machine 1 Machine 3 Machine 2
  • 9. The Greedy Method 9 Task Scheduling Algorithm Greedy choice: consider tasks by their start time and use as few machines as possible with this order.  Run time: O(n log n). Why? Correctness: Suppose there is a better schedule.  We can use k-1 machines  The algorithm uses k  Let i be first task scheduled on machine k  Machine i must conflict with k-1 other tasks  But that means there is no non-conflicting schedule using k-1 machines Algorithm taskSchedule(T) Input: set T of tasks w/ start time si and finish time fi Output: non-conflicting schedule with minimum number of machines m  0 {no. of machines} while T is not empty remove task i w/ smallest si if there’s a machine j for i then schedule i on machine j else m  m + 1 schedule i on machine m
  • 10. The Greedy Method 10 Example Given: a set T of n tasks, each having:  A start time, si  A finish time, fi (where si < fi)  [1,4], [1,3], [2,5], [3,7], [4,7], [6,9], [7,8] (ordered by start) Goal: Perform all tasks on min. number of machines 1 9 8 7 6 5 4 3 2 Machine 1 Machine 3 Machine 2

Editor's Notes

  • #2: 4/1/2022 1:40 PM