SlideShare a Scribd company logo
Algorithm Design Methods 
• Greedy method. 
• Divide and conquer. 
• Dynamic Programming. 
• Backtracking. 
• Branch and bound.
Some Methods Not Covered 
• Linear Programming. 
• Integer Programming. 
• Simulated Annealing. 
• Neural Networks. 
• Genetic Algorithms. 
• Tabu Search.
Optimization Problem 
A problem in which some function (called the 
optimization or objective function) is to be 
optimized (usually minimized or 
maximized) subject to some constraints.
Machine Scheduling 
Find a schedule that minimizes the finish time. 
• optimization function … finish time 
• constraints 
 each job is scheduled continuously on a single machine 
for an amount of time equal to its processing requirement 
 no machine processes more than one job at a time
Bin Packing 
Pack items into bins using the fewest number of 
bins. 
• optimization function … number of bins 
• constraints 
 each item is packed into a single bin 
 the capacity of no bin is exceeded
Min Cost Spanning Tree 
Find a spanning tree that has minimum cost. 
• optimization function … sum of edge costs 
• constraints 
 must select n-1edges of the given n vertex graph 
 the selected edges must form a tree
Feasible And Optimal Solutions 
A feasible solution is a solution that satisfies 
the constraints. 
An optimal solution is a feasible solution that 
optimizes the objective/optimization 
function.
Greedy Method 
• Solve problem by making a sequence of 
decisions. 
• Decisions are made one by one in some 
order. 
• Each decision is made using a greedy 
criterion. 
• A decision, once made, is (usually) not 
changed later.
Machine Scheduling 
LPT Scheduling. 
• Schedule jobs one by one and in decreasing order 
of processing time. 
• Each job is scheduled on the machine on which it 
finishes earliest. 
• Scheduling decisions are made serially using a 
greedy criterion (minimize finish time of this job). 
• LPT scheduling is an application of the greedy 
method.
LPT Schedule 
• LPT rule does not guarantee minimum finish 
time schedules. 
• (LPT Finish Time)/(Minimum Finish Time) <= 4/3 - 1/(3m) 
where m is number of machines 
• Minimum finish time scheduling is NP-hard. 
• In this case, the greedy method does not work. 
• The greedy method does, however, give us a 
good heuristic for machine scheduling.
Container Loading 
• Ship has capacity c. 
• m containers are available for loading. 
• Weight of container i is wi. 
• Each weight is a positive number. 
• Sum of container weights > c. 
• Load as many containers as is possible 
without sinking the ship.
Greedy Solution 
• Load containers in increasing order of 
weight until we get to a container that 
doesn’t fit. 
• Does this greedy algorithm always load the 
maximum number of containers? 
• Yes. May be proved using a proof by 
induction (see text).
Container Loading With 2 Ships 
Can all containers be loaded into 2 ships whose 
capacity is c (each)? 
• Same as bin packing with 2 bins. 
 Are 2 bins sufficient for all items? 
• Same as machine scheduling with 2 machines. 
 Can all jobs be completed by 2 machines in c time 
units? 
• NP-hard.
0/1 Knapsack Problem
0/1 Knapsack Problem 
• Hiker wishes to take n items on a trip. 
• The weight of item i is wi. 
• The items are to be carried in a knapsack whose 
weight capacity is c. 
• When sum of item weights <= c, all n items can 
be carried in the knapsack. 
• When sum of item weights > c, some items must 
be left behind. 
• Which items should be taken/left?
0/1 Knapsack Problem 
• Hiker assigns a profit/value pi to item i. 
• All weights and profits are positive numbers. 
• Hiker wants to select a subset of the n items to take. 
 The weight of the subset should not exceed the 
capacity of the knapsack. (constraint) 
 Cannot select a fraction of an item. (constraint) 
 The profit/value of the subset is the sum of the 
profits of the selected items. (optimization function) 
 The profit/value of the selected subset should be 
maximum. (optimization criterion)
0/1 Knapsack Problem 
Let xi = 1 when item i is selected and let xi = 0 
when item i is not selected. 
n 
maximize pi xi 
i = 1 
n 
subject to wx<= c 
i i i = 1 
and x= 0 or 1 for all i 
i
Greedy Attempt 1 
Be greedy on capacity utilization. 
 Select items in increasing order of weight. 
n = 2, c = 7 
w = [3, 6] 
p = [2, 10] 
only item 1 is selected 
profit (value) of selection is 2 
not best selection!
Greedy Attempt 2 
Be greedy on profit earned. 
 Select items in decreasing order of profit. 
n = 3, c = 7 
w = [7, 3, 2] 
p = [10, 8, 6] 
only item 1 is selected 
profit (value) of selection is 10 
not best selection!
Greedy Attempt 3 
Be greedy on profit density (p/w). 
 Select items in decreasing order of profit density. 
n = 2, c = 7 
w = [1, 7] 
p = [10, 20] 
only item 1 is selected 
profit (value) of selection is 10 
not best selection!
Greedy Attempt 3 
Be greedy on profit density (p/w). 
 Works when selecting a fraction of an item is 
permitted 
 Select items in decreasing order of profit density, if 
next item doesn’t fit take a fraction so as to fill 
knapsack. 
n = 2, c = 7 
w = [1, 7] 
p = [10, 20] 
item 1 and 6/7 of item 2 are selected
0/1 Knapsack Greedy Heuristics 
• Select a subset with <= k items. 
• If the weight of this subset is > c, discard 
the subset. 
• If the subset weight is <= c, fill as much of 
the remaining capacity as possible by being 
greedy on profit density. 
• Try all subsets with <= k items and select 
the one that yields maximum profit.
0/1 Knapsack Greedy Heuristics 
• (best value - greedy value)/(best value) <= 1/ 
(k+1) 
k 0% 1% 5% 10% 25% 
0 239 390 528 583 600 
1 360 527 598 600 
2 483 581 600 
Number of solutions (out ooff 660000)) wwiitthhiinn xx%% ooff bbeesstt..
0/1 Knapsack Greedy Heuristics 
• First sort into decreasing order of profit density. 
• There are O(nk) subsets with at most k items. 
• Trying a subset takes O(n) time. 
• Total time is O(nk+1) when k > 0. 
• (best value - greedy value)/(best value) <= 1/ 
(k+1)

More Related Content

What's hot (20)

Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Greedy method1
Greedy method1Greedy method1
Greedy method1
 
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
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
 
12 Greeddy Method
12 Greeddy Method12 Greeddy Method
12 Greeddy Method
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
lecture 26
lecture 26lecture 26
lecture 26
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
greedy algorithm Fractional Knapsack
greedy algorithmFractional Knapsack greedy algorithmFractional Knapsack
greedy algorithm Fractional Knapsack
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
Greedy method
Greedy methodGreedy method
Greedy method
 
A greedy algorithms
A greedy algorithmsA greedy algorithms
A greedy algorithms
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
36 greedy
36 greedy36 greedy
36 greedy
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategies
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 

Viewers also liked

Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound techniqueishmecse13
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
lecture 17
lecture 17lecture 17
lecture 17sajinsc
 
Application of greedy method prim
Application of greedy method primApplication of greedy method prim
Application of greedy method primTech_MX
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comHemant Gautam
 
Branch and bound
Branch and boundBranch and bound
Branch and boundAcad
 
Graph theory short presentation
Graph theory short presentationGraph theory short presentation
Graph theory short presentationmjr989
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structuresKàŕtheek Jåvvàjí
 
Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy methodTech_MX
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound techniqueishmecse13
 

Viewers also liked (20)

Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Knapsack
KnapsackKnapsack
Knapsack
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Lecture#9
Lecture#9Lecture#9
Lecture#9
 
lecture 17
lecture 17lecture 17
lecture 17
 
Heapsort using Heap
Heapsort using HeapHeapsort using Heap
Heapsort using Heap
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Application of greedy method prim
Application of greedy method primApplication of greedy method prim
Application of greedy method prim
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.com
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Branch & bound
Branch & boundBranch & bound
Branch & bound
 
Graph theory short presentation
Graph theory short presentationGraph theory short presentation
Graph theory short presentation
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
 
Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy method
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
 

Similar to Lec30

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 with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problemharsh kothari
 
Module 2 - Greedy Algorithm Data structures and algorithm
Module 2  - Greedy Algorithm  Data structures and algorithmModule 2  - Greedy Algorithm  Data structures and algorithm
Module 2 - Greedy Algorithm Data structures and algorithmfarzanirani201402
 
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
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"22bcs058
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4infanciaj
 
DRL #2-3 - Multi-Armed Bandits .pptx.pdf
DRL #2-3 - Multi-Armed Bandits .pptx.pdfDRL #2-3 - Multi-Armed Bandits .pptx.pdf
DRL #2-3 - Multi-Armed Bandits .pptx.pdfGulamSarwar31
 

Similar to Lec30 (20)

Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
greedy method.pdf
greedy method.pdfgreedy method.pdf
greedy method.pdf
 
Fractional knapsack problem
Fractional knapsack problemFractional knapsack problem
Fractional knapsack problem
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
 
Module 2 - Greedy Algorithm Data structures and algorithm
Module 2  - Greedy Algorithm  Data structures and algorithmModule 2  - Greedy Algorithm  Data structures and algorithm
Module 2 - Greedy Algorithm Data structures and algorithm
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
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
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
knapsack.pptx
knapsack.pptxknapsack.pptx
knapsack.pptx
 
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4
 
DRL #2-3 - Multi-Armed Bandits .pptx.pdf
DRL #2-3 - Multi-Armed Bandits .pptx.pdfDRL #2-3 - Multi-Armed Bandits .pptx.pdf
DRL #2-3 - Multi-Armed Bandits .pptx.pdf
 

More from Nikhil Chilwant (20)

The joyless economy
The joyless economyThe joyless economy
The joyless economy
 
I 7
I 7I 7
I 7
 
IIT Delhi training pioneer ct (acemicromatic )
IIT Delhi training pioneer ct (acemicromatic )IIT Delhi training pioneer ct (acemicromatic )
IIT Delhi training pioneer ct (acemicromatic )
 
Lec39
Lec39Lec39
Lec39
 
Lec38
Lec38Lec38
Lec38
 
Lec36
Lec36Lec36
Lec36
 
Lec35
Lec35Lec35
Lec35
 
Lec34
Lec34Lec34
Lec34
 
Lec33
Lec33Lec33
Lec33
 
Lec32
Lec32Lec32
Lec32
 
Lec29
Lec29Lec29
Lec29
 
Lec28
Lec28Lec28
Lec28
 
Lec27
Lec27Lec27
Lec27
 
Lec26
Lec26Lec26
Lec26
 
Lec25
Lec25Lec25
Lec25
 
Lec24
Lec24Lec24
Lec24
 
Lec23
Lec23Lec23
Lec23
 
Lec21
Lec21Lec21
Lec21
 
Lec20
Lec20Lec20
Lec20
 
Lec19
Lec19Lec19
Lec19
 

Lec30

  • 1. Algorithm Design Methods • Greedy method. • Divide and conquer. • Dynamic Programming. • Backtracking. • Branch and bound.
  • 2. Some Methods Not Covered • Linear Programming. • Integer Programming. • Simulated Annealing. • Neural Networks. • Genetic Algorithms. • Tabu Search.
  • 3. Optimization Problem A problem in which some function (called the optimization or objective function) is to be optimized (usually minimized or maximized) subject to some constraints.
  • 4. Machine Scheduling Find a schedule that minimizes the finish time. • optimization function … finish time • constraints  each job is scheduled continuously on a single machine for an amount of time equal to its processing requirement  no machine processes more than one job at a time
  • 5. Bin Packing Pack items into bins using the fewest number of bins. • optimization function … number of bins • constraints  each item is packed into a single bin  the capacity of no bin is exceeded
  • 6. Min Cost Spanning Tree Find a spanning tree that has minimum cost. • optimization function … sum of edge costs • constraints  must select n-1edges of the given n vertex graph  the selected edges must form a tree
  • 7. Feasible And Optimal Solutions A feasible solution is a solution that satisfies the constraints. An optimal solution is a feasible solution that optimizes the objective/optimization function.
  • 8. Greedy Method • Solve problem by making a sequence of decisions. • Decisions are made one by one in some order. • Each decision is made using a greedy criterion. • A decision, once made, is (usually) not changed later.
  • 9. Machine Scheduling LPT Scheduling. • Schedule jobs one by one and in decreasing order of processing time. • Each job is scheduled on the machine on which it finishes earliest. • Scheduling decisions are made serially using a greedy criterion (minimize finish time of this job). • LPT scheduling is an application of the greedy method.
  • 10. LPT Schedule • LPT rule does not guarantee minimum finish time schedules. • (LPT Finish Time)/(Minimum Finish Time) <= 4/3 - 1/(3m) where m is number of machines • Minimum finish time scheduling is NP-hard. • In this case, the greedy method does not work. • The greedy method does, however, give us a good heuristic for machine scheduling.
  • 11. Container Loading • Ship has capacity c. • m containers are available for loading. • Weight of container i is wi. • Each weight is a positive number. • Sum of container weights > c. • Load as many containers as is possible without sinking the ship.
  • 12. Greedy Solution • Load containers in increasing order of weight until we get to a container that doesn’t fit. • Does this greedy algorithm always load the maximum number of containers? • Yes. May be proved using a proof by induction (see text).
  • 13. Container Loading With 2 Ships Can all containers be loaded into 2 ships whose capacity is c (each)? • Same as bin packing with 2 bins.  Are 2 bins sufficient for all items? • Same as machine scheduling with 2 machines.  Can all jobs be completed by 2 machines in c time units? • NP-hard.
  • 15. 0/1 Knapsack Problem • Hiker wishes to take n items on a trip. • The weight of item i is wi. • The items are to be carried in a knapsack whose weight capacity is c. • When sum of item weights <= c, all n items can be carried in the knapsack. • When sum of item weights > c, some items must be left behind. • Which items should be taken/left?
  • 16. 0/1 Knapsack Problem • Hiker assigns a profit/value pi to item i. • All weights and profits are positive numbers. • Hiker wants to select a subset of the n items to take.  The weight of the subset should not exceed the capacity of the knapsack. (constraint)  Cannot select a fraction of an item. (constraint)  The profit/value of the subset is the sum of the profits of the selected items. (optimization function)  The profit/value of the selected subset should be maximum. (optimization criterion)
  • 17. 0/1 Knapsack Problem Let xi = 1 when item i is selected and let xi = 0 when item i is not selected. n maximize pi xi i = 1 n subject to wx<= c i i i = 1 and x= 0 or 1 for all i i
  • 18. Greedy Attempt 1 Be greedy on capacity utilization.  Select items in increasing order of weight. n = 2, c = 7 w = [3, 6] p = [2, 10] only item 1 is selected profit (value) of selection is 2 not best selection!
  • 19. Greedy Attempt 2 Be greedy on profit earned.  Select items in decreasing order of profit. n = 3, c = 7 w = [7, 3, 2] p = [10, 8, 6] only item 1 is selected profit (value) of selection is 10 not best selection!
  • 20. Greedy Attempt 3 Be greedy on profit density (p/w).  Select items in decreasing order of profit density. n = 2, c = 7 w = [1, 7] p = [10, 20] only item 1 is selected profit (value) of selection is 10 not best selection!
  • 21. Greedy Attempt 3 Be greedy on profit density (p/w).  Works when selecting a fraction of an item is permitted  Select items in decreasing order of profit density, if next item doesn’t fit take a fraction so as to fill knapsack. n = 2, c = 7 w = [1, 7] p = [10, 20] item 1 and 6/7 of item 2 are selected
  • 22. 0/1 Knapsack Greedy Heuristics • Select a subset with <= k items. • If the weight of this subset is > c, discard the subset. • If the subset weight is <= c, fill as much of the remaining capacity as possible by being greedy on profit density. • Try all subsets with <= k items and select the one that yields maximum profit.
  • 23. 0/1 Knapsack Greedy Heuristics • (best value - greedy value)/(best value) <= 1/ (k+1) k 0% 1% 5% 10% 25% 0 239 390 528 583 600 1 360 527 598 600 2 483 581 600 Number of solutions (out ooff 660000)) wwiitthhiinn xx%% ooff bbeesstt..
  • 24. 0/1 Knapsack Greedy Heuristics • First sort into decreasing order of profit density. • There are O(nk) subsets with at most k items. • Trying a subset takes O(n) time. • Total time is O(nk+1) when k > 0. • (best value - greedy value)/(best value) <= 1/ (k+1)

Editor's Notes

  1. Similar to truck loading.
  2. Same as ship loading to maximize earnings. Each container has a weight and profit.