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

Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
Arafat Hossan
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Lecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithmLecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithm
Hema Kashyap
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
A* Search Algorithm
A* Search AlgorithmA* Search Algorithm
A* Search Algorithm
vikas dhakane
 
Greedy method1
Greedy method1Greedy method1
Greedy method1
Rajendran
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
Dr Geetha Mohan
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Backtracking
Backtracking  Backtracking
Backtracking
Vikas Sharma
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
2.2 decision tree
2.2 decision tree2.2 decision tree
2.2 decision tree
Krish_ver2
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programming
maharajdey
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm propertiesLincoln School
 
Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian path
Arindam Ghosh
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
sandeep54552
 

What's hot (20)

Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Lecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithmLecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithm
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
A* Search Algorithm
A* Search AlgorithmA* Search Algorithm
A* Search Algorithm
 
Greedy method1
Greedy method1Greedy method1
Greedy method1
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Backtracking
Backtracking  Backtracking
Backtracking
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
2.2 decision tree
2.2 decision tree2.2 decision tree
2.2 decision tree
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programming
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
 
Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian path
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 

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.pdf
MAJDABDALLAH3
 
Unit V.pdf
Unit V.pdfUnit 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)
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 Strategies
Fulvio 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 solution
Rashid Ansari
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
Bansari Shah
 
algo classification.pptx
algo classification.pptxalgo classification.pptx
algo classification.pptx
ShivaniSharma335055
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
data structure and algorithm (Advanced algorithm Stretegies)
data structure and algorithm (Advanced algorithm Stretegies)data structure and algorithm (Advanced algorithm Stretegies)
data structure and algorithm (Advanced algorithm Stretegies)
shahghanikhan
 
problem characterstics.pptx
problem characterstics.pptxproblem characterstics.pptx
problem characterstics.pptx
PriyadharshiniG41
 
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
 
csce411-set7.ppt
csce411-set7.pptcsce411-set7.ppt
csce411-set7.ppt
JoshCasas1
 
algorithm design.pptx
algorithm design.pptxalgorithm design.pptx
algorithm design.pptx
ssuserd11e4a
 
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
Mohammed khaja Jamaluddin
 

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
 
data structure and algorithm (Advanced algorithm Stretegies)
data structure and algorithm (Advanced algorithm Stretegies)data structure and algorithm (Advanced algorithm Stretegies)
data structure and algorithm (Advanced algorithm Stretegies)
 
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
 

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
 
Raid technology
Raid technologyRaid technology
Raid technology
CHANDAN KUMAR
 
Pointers in c
Pointers in cPointers in c
Pointers in c
CHANDAN KUMAR
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
CHANDAN KUMAR
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
CHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
CHANDAN KUMAR
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
CHANDAN KUMAR
 
Linked List
Linked ListLinked List
Linked List
CHANDAN KUMAR
 
Stack and queue
Stack and queueStack and queue
Stack and queue
CHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
CHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 

More from CHANDAN KUMAR (12)

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
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
 
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

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 

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.