SlideShare a Scribd company logo
1 of 15
Prepared By:
Dr. Chandan Kumar
Assistant Professor, Computer Science & Engineering Department
Invertis University, Bareilly
Introduction
 To understand greedy algorithm, firstly we must know
about
 Optimization problem
 Feasible solution
 Optimal solution
Optimization Problem
 An optimization problem is one in which you want to find,
not just a solution, but the best solution
 An optimization problem which demands or requires
either minimum result or maximum result
Optimization Problem
 Example
P : X ------700 KM-------------->Y
Where P is a problem, X and Y are the locations.
Here, I want to travel from location X to location Y. Now,
for this problem may be more than one solutions. Such
as, S1- travel by auto S4- Travel by bus
S2- Travel by bike S5- Travel by train
S3- Travel by car S6- Travel by airplane
and so on
Optimization Problem
But here is a condition that complete this journey within 10
hours.
We cannot complete this journey by solutions S1, S2, S3 but
cover by solution S4,S5 and S6. Hence, solutions S4, S5 and
S6 are called feasible solutions ( A solution which satisfies a
condition for the given problem).
Now I want to cover this journey at minimum cost i.e. we
want to minimize the problem. Suppose the train fare is
minimum then solution S5 is called optimal solution.
Optimization Problem
 For any problem, there is only one optimal solution.
 Similarly, some problems required maximum results.
 Hence, if a problem requires either minimum or maximum
results than we call that type of problem as an optimization
problem.
 The greedy method is used for solving optimization
problems.
Optimization Problem
 For solving optimization problem there are three strategies
 Greedy Method
 Dynamic Programming
 Branch and Bound
Greedy Method
 Simplest and straightforward approach, among all the
algorithmic approaches.
 Easy to implement and quite efficient.
 Greedy algorithms build a solution part by part, choosing
the next part in such a way, that it gives an immediate
benefit. This approach never reconsiders the choices taken
previously.
 In this approach, the decision is taken on the basis of
currently available information without worrying about the
effect of the current decision in future.
Greedy Method
 Suppose that a problem can be solved by a sequence of
decisions. The greedy method has that each decision is locally
optimal. These locally optimal solutions will finally add up to
a globally optimal solution.
Greedy Algorithm
 The algorithm makes the optimal choice at each step as it
attempts to find the overall optimal way to solve the entire
problem.
• A greedy algorithm works in phases. At each phase:
– You take the best you can get right now, without regard
for future consequences
– You hope that by choosing a local optimum at each step,
you will end up at a global optimum
Greedy Algorithm
 Components- Greedy algorithms have the following five
components
 A candidate set − A solution is created from this set.
 A selection function − Used to choose the best
candidate to be added to the solution.
 A feasibility function − Used to determine whether a
candidate can be used to contribute to the solution.
 An objective function − Used to assign a value to a
solution or a partial solution.
 A solution function − Used to indicate whether a
complete solution has been reached.
Greedy Algorithm
 Steps for achieving a Greedy Algorithm are
 Feasible: Here we search to see whether it meets all
possible constraints or not, to get at least one solution to
our problems.
 Local Optimal Choice: In this, the optimal option that
is selected from the currently available should be
 Unalterable: After taking a decision , the choice is not
altered at any subsequent stage.
Algorithm
Algorithm Greedy (x,n) // n is an input size and x is an input
{
for i= 1 to n do
{
y=select(x);
if feasible(y) then
{
solution=solution + y;
}
}
}
Application
 Greedy method is used to solve a variety of problems
including
 Finding the shortest path between two vertices using
Dijkstra’s algorithm
 Finding the minimal spanning tree in a graph using
Prim’s /Kruskal’s algorithm
 Networking algorithm also uses greedy approach like
Travelling Salesman Problem, Graph - Map Coloring
,Graph - Vertex Cover, Knapsack Problem, Job
Scheduling Problem etc.
Greedy algorithm

More Related Content

What's hot

Fundamentals of algorithms
Fundamentals of algorithmsFundamentals of algorithms
Fundamentals of algorithmsAmit Kumar Rathi
 
Linear programming
Linear programmingLinear programming
Linear programmingKarnav Rana
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design PresentationKawsar Ahmed
 
LINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment helpLINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment helpjohn mayer
 
Mat 540 week 9 quiz 5
Mat 540 week 9  quiz 5  Mat 540 week 9  quiz 5
Mat 540 week 9 quiz 5 getwisdom
 
Introduction to linear programming
Introduction to linear programmingIntroduction to linear programming
Introduction to linear programmingn_cool001
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...Simplilearn
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithmNisha Soms
 
Ms 51 operations research
Ms 51 operations researchMs 51 operations research
Ms 51 operations researchsmumbahelp
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhanijyoti_lakhani
 
Fundamental Programming Lect 4
Fundamental Programming Lect 4Fundamental Programming Lect 4
Fundamental Programming Lect 4Namrah Erum
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
 
Algorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem SolvingAlgorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem Solvingcoolpie
 

What's hot (20)

Linear programing
Linear programingLinear programing
Linear programing
 
Fundamentals of algorithms
Fundamentals of algorithmsFundamentals of algorithms
Fundamentals of algorithms
 
Dynamic Programming | Economics
Dynamic Programming | EconomicsDynamic Programming | Economics
Dynamic Programming | Economics
 
Linear programming
Linear programmingLinear programming
Linear programming
 
Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 
LINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment helpLINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment help
 
Mat 540 week 9 quiz 5
Mat 540 week 9  quiz 5  Mat 540 week 9  quiz 5
Mat 540 week 9 quiz 5
 
Introduction to linear programming
Introduction to linear programmingIntroduction to linear programming
Introduction to linear programming
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
 
Problem solving
Problem solvingProblem solving
Problem solving
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithm
 
Ms 51 operations research
Ms 51 operations researchMs 51 operations research
Ms 51 operations research
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhani
 
Fundamental Programming Lect 4
Fundamental Programming Lect 4Fundamental Programming Lect 4
Fundamental Programming Lect 4
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
Cs 1114 - lecture-3
Cs 1114 - lecture-3Cs 1114 - lecture-3
Cs 1114 - lecture-3
 
Empirical analysis
Empirical analysisEmpirical analysis
Empirical analysis
 
Algorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem SolvingAlgorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem Solving
 

Similar to Greedy algorithm

Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms SURBHI SAROHA
 
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
 
0 1 knapsack problem(greedy algorithm)
0 1 knapsack problem(greedy algorithm)0 1 knapsack problem(greedy algorithm)
0 1 knapsack problem(greedy algorithm)SwatiRani13
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11Kumar
 
Search and Optimization Strategies
Search and Optimization StrategiesSearch and Optimization Strategies
Search and Optimization StrategiesFulvio Corno
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "CHANDAN KUMAR
 
Greedy aproach towards problem solution
Greedy aproach towards problem solutionGreedy aproach towards problem solution
Greedy aproach towards problem solutionRashid Ansari
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxsatvikkushwaha1
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of AlgorithmsBulbul Agrawal
 
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.pdfishan743441
 
csce411-set7.ppt
csce411-set7.pptcsce411-set7.ppt
csce411-set7.pptJoshCasas1
 
algorithm design.pptx
algorithm design.pptxalgorithm design.pptx
algorithm design.pptxssuserd11e4a
 
1.1 the introduction of design and analysis of algorithm
1.1 the introduction of design and analysis of algorithm1.1 the introduction of design and analysis of algorithm
1.1 the introduction of design and analysis of algorithmMohammed khaja Jamaluddin
 
Ai planning with evolutionary computing
Ai planning with evolutionary computingAi planning with evolutionary computing
Ai planning with evolutionary computingpinozz
 

Similar to Greedy algorithm (20)

Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms
 
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
 
Unit V.pdf
Unit V.pdfUnit V.pdf
Unit V.pdf
 
0 1 knapsack problem(greedy algorithm)
0 1 knapsack problem(greedy algorithm)0 1 knapsack problem(greedy algorithm)
0 1 knapsack problem(greedy algorithm)
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11
 
Search and Optimization Strategies
Search and Optimization StrategiesSearch and Optimization Strategies
Search and Optimization Strategies
 
mmmmmmm
mmmmmmmmmmmmmm
mmmmmmm
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
 
Greedy aproach towards problem solution
Greedy aproach towards problem solutionGreedy aproach towards problem solution
Greedy aproach towards problem solution
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
algo classification.pptx
algo classification.pptxalgo classification.pptx
algo classification.pptx
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
problem characterstics.pptx
problem characterstics.pptxproblem characterstics.pptx
problem characterstics.pptx
 
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
 
csce411-set7.ppt
csce411-set7.pptcsce411-set7.ppt
csce411-set7.ppt
 
algorithm design.pptx
algorithm design.pptxalgorithm design.pptx
algorithm design.pptx
 
1.1 the introduction of design and analysis of algorithm
1.1 the introduction of design and analysis of algorithm1.1 the introduction of design and analysis of algorithm
1.1 the introduction of design and analysis of algorithm
 
Ai planning with evolutionary computing
Ai planning with evolutionary computingAi planning with evolutionary computing
Ai planning with evolutionary computing
 

More from CHANDAN KUMAR

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language CHANDAN KUMAR
 
Searching in c language
Searching in c languageSearching in c language
Searching in c languageCHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programmingCHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programmingCHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 

More from CHANDAN KUMAR (11)

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Raid technology
Raid technologyRaid technology
Raid technology
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Linked List
Linked ListLinked List
Linked List
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 

Recently uploaded

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

Greedy algorithm

  • 1. Prepared By: Dr. Chandan Kumar Assistant Professor, Computer Science & Engineering Department Invertis University, Bareilly
  • 2. Introduction  To understand greedy algorithm, firstly we must know about  Optimization problem  Feasible solution  Optimal solution
  • 3. Optimization Problem  An optimization problem is one in which you want to find, not just a solution, but the best solution  An optimization problem which demands or requires either minimum result or maximum result
  • 4. Optimization Problem  Example P : X ------700 KM-------------->Y Where P is a problem, X and Y are the locations. Here, I want to travel from location X to location Y. Now, for this problem may be more than one solutions. Such as, S1- travel by auto S4- Travel by bus S2- Travel by bike S5- Travel by train S3- Travel by car S6- Travel by airplane and so on
  • 5. Optimization Problem But here is a condition that complete this journey within 10 hours. We cannot complete this journey by solutions S1, S2, S3 but cover by solution S4,S5 and S6. Hence, solutions S4, S5 and S6 are called feasible solutions ( A solution which satisfies a condition for the given problem). Now I want to cover this journey at minimum cost i.e. we want to minimize the problem. Suppose the train fare is minimum then solution S5 is called optimal solution.
  • 6. Optimization Problem  For any problem, there is only one optimal solution.  Similarly, some problems required maximum results.  Hence, if a problem requires either minimum or maximum results than we call that type of problem as an optimization problem.  The greedy method is used for solving optimization problems.
  • 7. Optimization Problem  For solving optimization problem there are three strategies  Greedy Method  Dynamic Programming  Branch and Bound
  • 8. Greedy Method  Simplest and straightforward approach, among all the algorithmic approaches.  Easy to implement and quite efficient.  Greedy algorithms build a solution part by part, choosing the next part in such a way, that it gives an immediate benefit. This approach never reconsiders the choices taken previously.  In this approach, the decision is taken on the basis of currently available information without worrying about the effect of the current decision in future.
  • 9. Greedy Method  Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These locally optimal solutions will finally add up to a globally optimal solution.
  • 10. Greedy Algorithm  The algorithm makes the optimal choice at each step as it attempts to find the overall optimal way to solve the entire problem. • A greedy algorithm works in phases. At each phase: – You take the best you can get right now, without regard for future consequences – You hope that by choosing a local optimum at each step, you will end up at a global optimum
  • 11. Greedy Algorithm  Components- Greedy algorithms have the following five components  A candidate set − A solution is created from this set.  A selection function − Used to choose the best candidate to be added to the solution.  A feasibility function − Used to determine whether a candidate can be used to contribute to the solution.  An objective function − Used to assign a value to a solution or a partial solution.  A solution function − Used to indicate whether a complete solution has been reached.
  • 12. Greedy Algorithm  Steps for achieving a Greedy Algorithm are  Feasible: Here we search to see whether it meets all possible constraints or not, to get at least one solution to our problems.  Local Optimal Choice: In this, the optimal option that is selected from the currently available should be  Unalterable: After taking a decision , the choice is not altered at any subsequent stage.
  • 13. Algorithm Algorithm Greedy (x,n) // n is an input size and x is an input { for i= 1 to n do { y=select(x); if feasible(y) then { solution=solution + y; } } }
  • 14. Application  Greedy method is used to solve a variety of problems including  Finding the shortest path between two vertices using Dijkstra’s algorithm  Finding the minimal spanning tree in a graph using Prim’s /Kruskal’s algorithm  Networking algorithm also uses greedy approach like Travelling Salesman Problem, Graph - Map Coloring ,Graph - Vertex Cover, Knapsack Problem, Job Scheduling Problem etc.