SlideShare a Scribd company logo
GREEDY METHOD
OUTLINE Greedy introduction Characteristics and features Optimization Problem Pseudo code for greedy algorithm Greedy approach The coin changing problem Container overloading Comparison with DP Pros and Cons
GREEDY INTRODUCTION Greedy algorithms are simple and straightforward. They are shortsighted in their approach A greedy algorithm is similar to a dynamic programming algorithm, but the difference is that solutions to the sub problems do not have to be known at each stage,  instead a "greedy" choice can be made of what looks best for the moment.
  CHARACTERISTICS AND FEATURES To construct the solution in an optimal way. Algorithm Maintains two sets,  -One contains chosen items and  -The other contains rejected items. Greedy algorithms make  good local choices  in the hope that They result in,  -An optimal solution.  -Feasible solutions.
CONTINUED… The greedy algorithm consists of four (4) function. A function that checks whether chosen set of items provide a solution.  A function that checks the feasibility of a set.  The selection function tells which of the items is the most promising.  An objective function, which does not appear explicitly, gives the value of a solution.
OPTIMIZATION PROBLEMS An optimization problem:  Given a problem instance, a set of  constraints  and an  objective function .  Find a  feasible  solution for the given instance for which the objective function has an optimal value. Either maximum or minimum depending on the problem being solved.A feasible solution that does this is called  optimal solution .
Continued… Feasible : A feasible solution satisfies the problem’s constraints Constraints : The constraints   specify the limitations on the required solutions.
GREEDY PROPERTY It consists of two property, 1. " greedy-choice property " ->It says that a globally optimal solution can be arrived at by making a locally optimal choice. 2. " optimal substructure " ->A problem exhibits optimal substructure if an optimal solution to the problem contains optimal solutions to the sub-problems. are two ingredients in the problem that lend to a greedy strategy.
Pseudo-code for Greedy Algorithm Algorithm Greedy (a,n) //a[1:n]contains the n inputs. { solution:=0;//initialize the solution. for i:=1 to n do  { x:=Select(a);   if  Feasible( solution, x) then solution:=Union(solution,x); } return solution; }
CONTINUED… Select ()  selects an input from a[] and removes it. the selected input value is assigned to x. Feasible ()  is a boolean-valued function that determines whether x can be included into the solution vector(no constraints are violated). Union()  combines x with the solution and updates the objective function.
  GREEDY APPROACH Greedy Algorithm works by making the decision that seems most promising at any moment; it never reconsiders this decision, whatever situation may arise later.   As an example consider the problem of  " Making Change". Coins available are: 100 cents 25 cents 10 cents 5 cents 1 cent
CONTINUED… Problem:   Make a change of a given amount using the smallest possible number of coins. Solution: The coin is selected using greedy criterion: at each stage increases the total amount of change constructed as much as possible. To assure feasibility i.e., the change given exactly equals the desired amount of the solution
Coin changing problem Algorithm: Make change for n units using the least possible number of coins. MAKE-CHANGE (n)          C ← {100, 25, 10, 5, 1}     // constant. S← {};                  // set that will hold the solution set.      Sum ← 0 sum of item in solution set   WHILE  sum not = n      x = largest item in set C such that sum + x ≤ n       IF  no such item  THEN            RETURN     "No Solution"      S ← S {value of x}      sum ← sum + x    RETURN  S
CONTAINER OVERLOADING  The overall Time complexity of loading container is  O ( n log n )
CONTINUED… Algorithm Container Loading(c,capacity,number of containers,x ) //greedy algorithm for container loading  //set x[i]=1 iff container c[i],i>=1 is loaded. { //sort into increasing order of weight Sort(c,number of Containers); n:=number of Containers; //initialize x for i:=1 to n do x[i]:=0;
CONTINUED… //select containers in order of weight  i :=1; While (i<=n&& c[i].weight<=capacity) { //enough capacity for container c[i].id X[c[i].id]:=1; Capacity-=c[i].weight;//remaining capacity i++; } }
COMPARISON WITH DP Greedy and Dynamic Programming are methods for solving optimization problems. Greedy algorithms are usually more efficient than DP solutions. However, often you need to use dynamic programming since the optimal solution cannot be guaranteed by a greedy algorithm. DP provides efficient solutions for some problems for which a brute force approach would be very slow
PROS AND CONS PROS: They are easier to implement,  they require much less computing resources,  they are much faster to execute.  Greedy algorithms are used to solve optimization problems CONS: Their only disadvantage being that they not always reach the global optimum solution; on the other hand, even when the global optimum solution is not reached, most of the times the reached sub-optimal solution is a very good solution.
Greedymethod
Ad

More Related Content

What's hot (20)

Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Agents in Artificial intelligence
Agents in Artificial intelligence Agents in Artificial intelligence
Agents in Artificial intelligence
Lalit Birla
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
Rezwan Siam
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Hill climbing
Hill climbingHill climbing
Hill climbing
Mohammad Faizan
 
Decision trees in Machine Learning
Decision trees in Machine Learning Decision trees in Machine Learning
Decision trees in Machine Learning
Mohammad Junaid Khan
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
Ai 03 solving_problems_by_searching
Ai 03 solving_problems_by_searchingAi 03 solving_problems_by_searching
Ai 03 solving_problems_by_searching
Mohammed Romi
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
srutisenpatra
 
Non- Deterministic Algorithms
Non- Deterministic AlgorithmsNon- Deterministic Algorithms
Non- Deterministic Algorithms
Dipankar Boruah
 
State space search and Problem Solving techniques
State space search and Problem Solving techniquesState space search and Problem Solving techniques
State space search and Problem Solving techniques
Kirti Verma
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
Vishal Singh
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Ensemble learning
Ensemble learningEnsemble learning
Ensemble learning
Haris Jamil
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
weak slot and filler structure
weak slot and filler structureweak slot and filler structure
weak slot and filler structure
Amey Kerkar
 
Heuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.pptHeuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.ppt
karthikaparthasarath
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Dr Shashikant Athawale
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Agents in Artificial intelligence
Agents in Artificial intelligence Agents in Artificial intelligence
Agents in Artificial intelligence
Lalit Birla
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
Rezwan Siam
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Decision trees in Machine Learning
Decision trees in Machine Learning Decision trees in Machine Learning
Decision trees in Machine Learning
Mohammad Junaid Khan
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHMI. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
Ai 03 solving_problems_by_searching
Ai 03 solving_problems_by_searchingAi 03 solving_problems_by_searching
Ai 03 solving_problems_by_searching
Mohammed Romi
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
srutisenpatra
 
Non- Deterministic Algorithms
Non- Deterministic AlgorithmsNon- Deterministic Algorithms
Non- Deterministic Algorithms
Dipankar Boruah
 
State space search and Problem Solving techniques
State space search and Problem Solving techniquesState space search and Problem Solving techniques
State space search and Problem Solving techniques
Kirti Verma
 
Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
Vishal Singh
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Ensemble learning
Ensemble learningEnsemble learning
Ensemble learning
Haris Jamil
 
weak slot and filler structure
weak slot and filler structureweak slot and filler structure
weak slot and filler structure
Amey Kerkar
 
Heuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.pptHeuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.ppt
karthikaparthasarath
 

Similar to Greedymethod (20)

Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
Bansari Shah
 
esign and Analysis of Algorithms Presentation.pptx
esign and Analysis of Algorithms Presentation.pptxesign and Analysis of Algorithms Presentation.pptx
esign and Analysis of Algorithms Presentation.pptx
Niraj759370
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
Ashwin Shiv
 
linear programming
linear programming linear programming
linear programming
DagnaygebawGoshme
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
CHANDAN KUMAR
 
Unit.2. linear programming
Unit.2. linear programmingUnit.2. linear programming
Unit.2. linear programming
DagnaygebawGoshme
 
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 Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
B.Kirron Reddi
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTES
suthi
 
Greedy aproach towards problem solution
Greedy aproach towards problem solutionGreedy aproach towards problem solution
Greedy aproach towards problem solution
Rashid Ansari
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptxdaa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
ashish bansal
 
Unit V.pdf
Unit V.pdfUnit V.pdf
Unit V.pdf
KPRevathiAsstprofITD
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
jinalgoti
 
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
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
esign and Analysis of Algorithms Presentation.pptx
esign and Analysis of Algorithms Presentation.pptxesign and Analysis of Algorithms Presentation.pptx
esign and Analysis of Algorithms Presentation.pptx
Niraj759370
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
Ashwin Shiv
 
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
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTES
suthi
 
Greedy aproach towards problem solution
Greedy aproach towards problem solutionGreedy aproach towards problem solution
Greedy aproach towards problem solution
Rashid Ansari
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptxdaa18d8d-d333-4398-94dd-a46802d88d79.pptx
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
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
 
Ad

More from Meenakshi Devi (7)

Good habits
Good habitsGood habits
Good habits
Meenakshi Devi
 
Ns2programs
Ns2programsNs2programs
Ns2programs
Meenakshi Devi
 
Study of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proramStudy of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proram
Meenakshi Devi
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Meenakshi Devi
 
Mobile computing seminar
Mobile computing seminarMobile computing seminar
Mobile computing seminar
Meenakshi Devi
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimization
Meenakshi Devi
 
Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Asychronous transfer mode(atm)
Asychronous transfer mode(atm)
Meenakshi Devi
 
Study of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proramStudy of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proram
Meenakshi Devi
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Meenakshi Devi
 
Mobile computing seminar
Mobile computing seminarMobile computing seminar
Mobile computing seminar
Meenakshi Devi
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimization
Meenakshi Devi
 
Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Asychronous transfer mode(atm)
Asychronous transfer mode(atm)
Meenakshi Devi
 
Ad

Recently uploaded (20)

The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho..."Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
ruslana1975
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho..."Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
"Heraldry Detective Project"- Coats of Arms and Mottos of "Ivanhoe" in Ivanho...
ruslana1975
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 

Greedymethod

  • 2. OUTLINE Greedy introduction Characteristics and features Optimization Problem Pseudo code for greedy algorithm Greedy approach The coin changing problem Container overloading Comparison with DP Pros and Cons
  • 3. GREEDY INTRODUCTION Greedy algorithms are simple and straightforward. They are shortsighted in their approach A greedy algorithm is similar to a dynamic programming algorithm, but the difference is that solutions to the sub problems do not have to be known at each stage, instead a &quot;greedy&quot; choice can be made of what looks best for the moment.
  • 4. CHARACTERISTICS AND FEATURES To construct the solution in an optimal way. Algorithm Maintains two sets, -One contains chosen items and -The other contains rejected items. Greedy algorithms make good local choices in the hope that They result in, -An optimal solution. -Feasible solutions.
  • 5. CONTINUED… The greedy algorithm consists of four (4) function. A function that checks whether chosen set of items provide a solution. A function that checks the feasibility of a set. The selection function tells which of the items is the most promising. An objective function, which does not appear explicitly, gives the value of a solution.
  • 6. OPTIMIZATION PROBLEMS An optimization problem: Given a problem instance, a set of constraints and an objective function . Find a feasible solution for the given instance for which the objective function has an optimal value. Either maximum or minimum depending on the problem being solved.A feasible solution that does this is called optimal solution .
  • 7. Continued… Feasible : A feasible solution satisfies the problem’s constraints Constraints : The constraints specify the limitations on the required solutions.
  • 8. GREEDY PROPERTY It consists of two property, 1. &quot; greedy-choice property &quot; ->It says that a globally optimal solution can be arrived at by making a locally optimal choice. 2. &quot; optimal substructure &quot; ->A problem exhibits optimal substructure if an optimal solution to the problem contains optimal solutions to the sub-problems. are two ingredients in the problem that lend to a greedy strategy.
  • 9. Pseudo-code for Greedy Algorithm Algorithm Greedy (a,n) //a[1:n]contains the n inputs. { solution:=0;//initialize the solution. for i:=1 to n do { x:=Select(a); if Feasible( solution, x) then solution:=Union(solution,x); } return solution; }
  • 10. CONTINUED… Select () selects an input from a[] and removes it. the selected input value is assigned to x. Feasible () is a boolean-valued function that determines whether x can be included into the solution vector(no constraints are violated). Union() combines x with the solution and updates the objective function.
  • 11. GREEDY APPROACH Greedy Algorithm works by making the decision that seems most promising at any moment; it never reconsiders this decision, whatever situation may arise later. As an example consider the problem of &quot; Making Change&quot;. Coins available are: 100 cents 25 cents 10 cents 5 cents 1 cent
  • 12. CONTINUED… Problem: Make a change of a given amount using the smallest possible number of coins. Solution: The coin is selected using greedy criterion: at each stage increases the total amount of change constructed as much as possible. To assure feasibility i.e., the change given exactly equals the desired amount of the solution
  • 13. Coin changing problem Algorithm: Make change for n units using the least possible number of coins. MAKE-CHANGE (n)         C ← {100, 25, 10, 5, 1}     // constant. S← {};                  // set that will hold the solution set.    Sum ← 0 sum of item in solution set   WHILE sum not = n      x = largest item in set C such that sum + x ≤ n       IF no such item THEN           RETURN     &quot;No Solution&quot;      S ← S {value of x}      sum ← sum + x    RETURN S
  • 14. CONTAINER OVERLOADING The overall Time complexity of loading container is O ( n log n )
  • 15. CONTINUED… Algorithm Container Loading(c,capacity,number of containers,x ) //greedy algorithm for container loading //set x[i]=1 iff container c[i],i>=1 is loaded. { //sort into increasing order of weight Sort(c,number of Containers); n:=number of Containers; //initialize x for i:=1 to n do x[i]:=0;
  • 16. CONTINUED… //select containers in order of weight i :=1; While (i<=n&& c[i].weight<=capacity) { //enough capacity for container c[i].id X[c[i].id]:=1; Capacity-=c[i].weight;//remaining capacity i++; } }
  • 17. COMPARISON WITH DP Greedy and Dynamic Programming are methods for solving optimization problems. Greedy algorithms are usually more efficient than DP solutions. However, often you need to use dynamic programming since the optimal solution cannot be guaranteed by a greedy algorithm. DP provides efficient solutions for some problems for which a brute force approach would be very slow
  • 18. PROS AND CONS PROS: They are easier to implement, they require much less computing resources, they are much faster to execute. Greedy algorithms are used to solve optimization problems CONS: Their only disadvantage being that they not always reach the global optimum solution; on the other hand, even when the global optimum solution is not reached, most of the times the reached sub-optimal solution is a very good solution.
  翻译: