SlideShare a Scribd company logo
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
Ad

More Related Content

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

Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdfLec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
MAJDABDALLAH3
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Jay Patel
 
12 Greeddy Method
12 Greeddy Method12 Greeddy Method
12 Greeddy Method
Andres Mendez-Vazquez
 
data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4
infanciaj
 
Unit V.pdf
Unit V.pdfUnit V.pdf
Unit V.pdf
KPRevathiAsstprofITD
 
Design and Analysis of Algorithms (Greedy Algorithm)
Design and Analysis of Algorithms (Greedy Algorithm)Design and Analysis of Algorithms (Greedy Algorithm)
Design and Analysis of Algorithms (Greedy Algorithm)
SababAshfakFahim
 
Fractional knapsack problem
Fractional knapsack problemFractional knapsack problem
Fractional knapsack problem
Learning Courses Online
 
Greedy Method unit-2(Design and analysis of algorithms).pptx
Greedy Method unit-2(Design and analysis of algorithms).pptxGreedy Method unit-2(Design and analysis of algorithms).pptx
Greedy Method unit-2(Design and analysis of algorithms).pptx
shivani366010
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Knapsack prooblem using greedy based algoithm
Knapsack prooblem using greedy based algoithmKnapsack prooblem using greedy based algoithm
Knapsack prooblem using greedy based algoithm
RICHARDACHARYA
 
Elak1 greedy presentation for design and analysis of algorithms.ppt
Elak1 greedy presentation for design and analysis of algorithms.pptElak1 greedy presentation for design and analysis of algorithms.ppt
Elak1 greedy presentation for design and analysis of algorithms.ppt
Elakkiya Rajasekar
 
Introduction to Optimization revised.ppt
Introduction to Optimization revised.pptIntroduction to Optimization revised.ppt
Introduction to Optimization revised.ppt
JahnaviGautam
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
Krish_ver2
 
376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt
RohitPaul71
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
Shiwani Gupta
 
linear programming
linear programming linear programming
linear programming
DagnaygebawGoshme
 
greedy algorithm.pptx good for understanding
greedy algorithm.pptx good for understandinggreedy algorithm.pptx good for understanding
greedy algorithm.pptx good for understanding
HUSNAINAHMAD39
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
Nikitagupta123
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
B.Kirron Reddi
 
Introduction to Greedy method, 0/1 Knapsack problem
Introduction to Greedy method, 0/1 Knapsack problemIntroduction to Greedy method, 0/1 Knapsack problem
Introduction to Greedy method, 0/1 Knapsack problem
DrSMeenakshiSundaram1
 
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdfLec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
MAJDABDALLAH3
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Jay Patel
 
data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4
infanciaj
 
Design and Analysis of Algorithms (Greedy Algorithm)
Design and Analysis of Algorithms (Greedy Algorithm)Design and Analysis of Algorithms (Greedy Algorithm)
Design and Analysis of Algorithms (Greedy Algorithm)
SababAshfakFahim
 
Greedy Method unit-2(Design and analysis of algorithms).pptx
Greedy Method unit-2(Design and analysis of algorithms).pptxGreedy Method unit-2(Design and analysis of algorithms).pptx
Greedy Method unit-2(Design and analysis of algorithms).pptx
shivani366010
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Knapsack prooblem using greedy based algoithm
Knapsack prooblem using greedy based algoithmKnapsack prooblem using greedy based algoithm
Knapsack prooblem using greedy based algoithm
RICHARDACHARYA
 
Elak1 greedy presentation for design and analysis of algorithms.ppt
Elak1 greedy presentation for design and analysis of algorithms.pptElak1 greedy presentation for design and analysis of algorithms.ppt
Elak1 greedy presentation for design and analysis of algorithms.ppt
Elakkiya Rajasekar
 
Introduction to Optimization revised.ppt
Introduction to Optimization revised.pptIntroduction to Optimization revised.ppt
Introduction to Optimization revised.ppt
JahnaviGautam
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
Krish_ver2
 
376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt376951072-3-Greedy-Method-new-ppt.ppt
376951072-3-Greedy-Method-new-ppt.ppt
RohitPaul71
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
Shiwani Gupta
 
greedy algorithm.pptx good for understanding
greedy algorithm.pptx good for understandinggreedy algorithm.pptx good for understanding
greedy algorithm.pptx good for understanding
HUSNAINAHMAD39
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
Nikitagupta123
 
Introduction to Greedy method, 0/1 Knapsack problem
Introduction to Greedy method, 0/1 Knapsack problemIntroduction to Greedy method, 0/1 Knapsack problem
Introduction to Greedy method, 0/1 Knapsack problem
DrSMeenakshiSundaram1
 

More from Ruchika Sinha (20)

Python Programming Introduction - Loops & Boolean
Python Programming Introduction  - Loops & BooleanPython Programming Introduction  - Loops & Boolean
Python Programming Introduction - Loops & Boolean
Ruchika Sinha
 
Difference Between Normal & Smart/Automated Home
Difference Between Normal & Smart/Automated HomeDifference Between Normal & Smart/Automated Home
Difference Between Normal & Smart/Automated Home
Ruchika Sinha
 
Greedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.pptGreedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.ppt
Ruchika Sinha
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.ppt
Ruchika Sinha
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
Ruchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
Ruchika Sinha
 
Clipping
ClippingClipping
Clipping
Ruchika Sinha
 
Lec22 intel
Lec22 intelLec22 intel
Lec22 intel
Ruchika Sinha
 
Pc assembly
Pc assemblyPc assembly
Pc assembly
Ruchika Sinha
 
Casing
CasingCasing
Casing
Ruchika Sinha
 
Installation of motherboard
Installation of motherboardInstallation of motherboard
Installation of motherboard
Ruchika Sinha
 
Shortest path
Shortest pathShortest path
Shortest path
Ruchika Sinha
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
Ruchika Sinha
 
Python material
Python materialPython material
Python material
Ruchika Sinha
 
Python3
Python3Python3
Python3
Ruchika Sinha
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
Ruchika Sinha
 
Software Teting
Software TetingSoftware Teting
Software Teting
Ruchika Sinha
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
Ruchika Sinha
 
Python Programming Introduction - Loops & Boolean
Python Programming Introduction  - Loops & BooleanPython Programming Introduction  - Loops & Boolean
Python Programming Introduction - Loops & Boolean
Ruchika Sinha
 
Difference Between Normal & Smart/Automated Home
Difference Between Normal & Smart/Automated HomeDifference Between Normal & Smart/Automated Home
Difference Between Normal & Smart/Automated Home
Ruchika Sinha
 
Greedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.pptGreedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.ppt
Ruchika Sinha
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.ppt
Ruchika Sinha
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.ppt
Ruchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
Ruchika Sinha
 
Installation of motherboard
Installation of motherboardInstallation of motherboard
Installation of motherboard
Ruchika Sinha
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
Ruchika Sinha
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
Ruchika Sinha
 
Ad

Recently uploaded (20)

Construction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.pptConstruction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.ppt
ssuser2ffcbc
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Environment .................................
Environment .................................Environment .................................
Environment .................................
shadyozq9
 
PPT on Sattelite satellite & Radar(1).pptx
PPT on Sattelite satellite & Radar(1).pptxPPT on Sattelite satellite & Radar(1).pptx
PPT on Sattelite satellite & Radar(1).pptx
navneet19791
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdfIBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
VigneshPalaniappanM
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
David Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And PythonDavid Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And Python
David Boutry
 
Construction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.pptConstruction-Chemicals-For-Waterproofing.ppt
Construction-Chemicals-For-Waterproofing.ppt
ssuser2ffcbc
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Environment .................................
Environment .................................Environment .................................
Environment .................................
shadyozq9
 
PPT on Sattelite satellite & Radar(1).pptx
PPT on Sattelite satellite & Radar(1).pptxPPT on Sattelite satellite & Radar(1).pptx
PPT on Sattelite satellite & Radar(1).pptx
navneet19791
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdfIBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
VigneshPalaniappanM
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Applications of Centroid in Structural Engineering
Applications of Centroid in Structural EngineeringApplications of Centroid in Structural Engineering
Applications of Centroid in Structural Engineering
suvrojyotihalder2006
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
David Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And PythonDavid Boutry - Specializes In AWS, Microservices And Python
David Boutry - Specializes In AWS, Microservices And Python
David Boutry
 
Ad

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: 12/5/2022 4:19 AM
  翻译: