SlideShare a Scribd company logo
1 of 10
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

Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy AlgorithmWaqar Akram
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problemsJyotsna Suryadevara
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEMi i
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
NP Complete Problems
NP Complete ProblemsNP Complete Problems
NP Complete ProblemsNikhil Joshi
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)swapnac12
 
Activation function
Activation functionActivation function
Activation functionAstha Jain
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1Kumar
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8Hakky St
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic ProgrammingFenil Shah
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and boundAbhishek Singh
 

What's hot (20)

Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
NP Complete Problems
NP Complete ProblemsNP Complete Problems
NP Complete Problems
 
Branch & bound
Branch & boundBranch & bound
Branch & bound
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
Activation function
Activation functionActivation function
Activation function
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
 
Greedy method
Greedy method Greedy method
Greedy method
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 

Similar to Greedy with Task Scheduling Algorithm.ppt

Greedy method1
Greedy method1Greedy method1
Greedy method1Rajendran
 
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.pdfMAJDABDALLAH3
 
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'sJay Patel
 
data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4infanciaj
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Introduction to Optimization revised.ppt
Introduction to Optimization revised.pptIntroduction to Optimization revised.ppt
Introduction to Optimization revised.pptJahnaviGautam
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02Krish_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.pptRohitPaul71
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfShiwani Gupta
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithmNikitagupta123
 

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

Greedy
GreedyGreedy
Greedy
 
Greedy method1
Greedy method1Greedy method1
Greedy method1
 
Lec30
Lec30Lec30
Lec30
 
Greedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. MohiteGreedy method by Dr. B. J. Mohite
Greedy method by Dr. B. J. Mohite
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
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
 
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
 
12 Greeddy Method
12 Greeddy Method12 Greeddy Method
12 Greeddy Method
 
data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4
 
Unit V.pdf
Unit V.pdfUnit V.pdf
Unit V.pdf
 
Fractional knapsack problem
Fractional knapsack problemFractional knapsack problem
Fractional knapsack problem
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Introduction to Optimization revised.ppt
Introduction to Optimization revised.pptIntroduction to Optimization revised.ppt
Introduction to Optimization revised.ppt
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
 
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
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
 
linear programming
linear programming linear programming
linear programming
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
 

More from 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.pptRuchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.pptRuchika Sinha
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.pptRuchika Sinha
 
Installation of motherboard
Installation of motherboardInstallation of motherboard
Installation of motherboardRuchika Sinha
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithmRuchika Sinha
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithmRuchika Sinha
 
Software for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentationSoftware for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentationRuchika Sinha
 

More from Ruchika Sinha (20)

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
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Greedy Algorithms Huffman Coding.ppt
Greedy Algorithms  Huffman Coding.pptGreedy Algorithms  Huffman Coding.ppt
Greedy Algorithms Huffman Coding.ppt
 
DynProg_Knapsack.ppt
DynProg_Knapsack.pptDynProg_Knapsack.ppt
DynProg_Knapsack.ppt
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
Clipping
ClippingClipping
Clipping
 
Lec22 intel
Lec22 intelLec22 intel
Lec22 intel
 
Pc assembly
Pc assemblyPc assembly
Pc assembly
 
Casing
CasingCasing
Casing
 
Installation of motherboard
Installation of motherboardInstallation of motherboard
Installation of motherboard
 
Shortest path
Shortest pathShortest path
Shortest path
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Python material
Python materialPython material
Python material
 
Python3
Python3Python3
Python3
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
 
Software Teting
Software TetingSoftware Teting
Software Teting
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
 
XML
XMLXML
XML
 
Software for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentationSoftware for encrypting and decrypting text file powerpointpresentation
Software for encrypting and decrypting text file powerpointpresentation
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 

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

  1. 4/1/2022 1:40 PM