SlideShare a Scribd company logo
1 of 20
• Greedy Algorithm
Optimization and Optimal value
• Any problem which could be solved using
more than one way is called an optimization
problem. For instance, we travel from one
point to another and we have more than one
routes.
• When we reach to our destination at a lowest
possible cost, it is the optimal value.
Commonly used optimization algorithms
• Greedy Algorithm
• Dynamic Programming
Greedy Algorithm
• Before explaining it, lets see a
scenario.
• Since she has no pockets in her
trouser, she needs coins as less as
possible.
• The problem to be solved here is
to give her 85 dollars with less
possible coins.
Available coins with Alex
Options are:
• Bags full of 50, 20, 10 and 5
dollars coins only
What are available options
• We have all these possible
options + more
Optimal value at each step
• Greedy algorithm selects the
minimum or maximum (in this
case) at each step.
What is Greedy Algorithm
• It is an optimization problem-solving method which selects the locally
optimal (i.e. maximum or minimum in the available) choice at each
step and hope it achieve the global optimum.
• Greedy Algorithms work step-by-step, and always choose the steps
which provide immediate profit/benefit.
• It chooses the “locally optimal solution”, without thinking about future
consequences.
What is Greedy Algorithm
• Greedy algorithms may not always lead to the optimal global solution,
because it does not consider the entire data.
• The choice made by the greedy approach does not consider future data
and choices.
• In some cases making a decision that looks right at that moment gives
the best solution (Greedy), but in other cases, it doesn’t.
Greedy Example
Do Greedy Algorithm always find global optimal? No
Dynamic Programming
• Most of the optimization algorithms (e.g. Greedy) work on simple princple;
solve the components of the main problem (i.e. subproblem), combine these
sub-solutions and get to an overall solution.
• Many subproblems are created and solved repeatedly . To reduce the number
of computations, the Dynamic Programming approach aims to answer each
subproblem just once.
• Once the solution to a given subproblem has been computed, it is saved or
"memoized," making it easy to find the next time the exact solution is required.
Dynamic Programming
• In daily life, we are using the aproach of
dynamic programming but we dont notice it.
• We ask a kid to count the sticks, he counts and
correctly answer of “4”
We actually applied dynamic programming
• We add another stick and ask
again, he doesn’t count it again
and still says the answer as 5.
• The kid memorize the previous
answer and hence, no need to
count it again.
1. Optimal substructures
• If the overall optimal solution of a problem can be determined from the optimal
solutions of its subproblems, this is referred to as having an optimal substructure
property.
• We are aware that the nth Fibonacci number, or Fib(n), is nothing more than the
sum of the two preceding Fibonacci numbers, or Fib(n) = Fib(n-1) + Fib (n-2).
• A problem of size 'n' has been divided into subproblems of sizes 'n-1' and 'n-2,' as
shown by the equation above.
2. Overlapping Subproblems
• If addressing the same subproblem occur more than once , that
subproblem is said to have overlapping subproblems.
An example of Fibonacci numbers
• Let's think about analyzing Fib (5). We can
see that Fib(5) is calculated by taking the
sum of Fib(4) and Fib(3), and Fib(4) is
calculated by taking the sum of Fib(3) and
Fib(2), and so on.
• Fib(3), Fib(2), Fib(1), and Fib(0) have all
undergone repeated evaluation. These are
nothing more than converging sub-
Problems.
Greedy vs Dynamic Programming
Greedy
• No guarantee of getting optimal
solution
• Efficient in terms of memory.
• Fast algorithm
Dynamic Programming
• Optimal solution is guaranteed as it
generally considers all possible cases and
then choose the best.
• It stores previous results, so consumes
memory.
• Comparatively slow
• Thank you

More Related Content

Similar to Greedy algorithm for design and analysis

Similar to Greedy algorithm for design and analysis (20)

Algorithm types
Algorithm typesAlgorithm types
Algorithm types
 
Types of algorithms
Types of algorithmsTypes of algorithms
Types of algorithms
 
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
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
 
Algo_Lecture01.pptx
Algo_Lecture01.pptxAlgo_Lecture01.pptx
Algo_Lecture01.pptx
 
algo classification.pptx
algo classification.pptxalgo classification.pptx
algo classification.pptx
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
 
Greedy is Good
Greedy is GoodGreedy is Good
Greedy is Good
 
Greedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.pptGreedy Algorithms WITH Activity Selection Problem.ppt
Greedy Algorithms WITH Activity Selection Problem.ppt
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Unit V.pdf
Unit V.pdfUnit V.pdf
Unit V.pdf
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Algorithms 1
Algorithms 1Algorithms 1
Algorithms 1
 
NC-NETS Employability Skills: Problem Solving
NC-NETS Employability Skills: Problem SolvingNC-NETS Employability Skills: Problem Solving
NC-NETS Employability Skills: Problem Solving
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Algorithms and how to write an algorithms
Algorithms and how to write an algorithmsAlgorithms and how to write an algorithms
Algorithms and how to write an algorithms
 

More from JavedKhan524377

Linear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmLinear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmJavedKhan524377
 
Binary Search Tree for design and analysis
Binary Search Tree for design and analysisBinary Search Tree for design and analysis
Binary Search Tree for design and analysisJavedKhan524377
 
Software Engineering Book for beginnerss
Software Engineering Book for beginnerssSoftware Engineering Book for beginnerss
Software Engineering Book for beginnerssJavedKhan524377
 
Software tetsing paper related to industry
Software tetsing paper related to industrySoftware tetsing paper related to industry
Software tetsing paper related to industryJavedKhan524377
 
Week 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learningWeek 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learningJavedKhan524377
 
lecture_for programming and computing basics
lecture_for programming and computing basicslecture_for programming and computing basics
lecture_for programming and computing basicsJavedKhan524377
 
chapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineeringchapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineeringJavedKhan524377
 

More from JavedKhan524377 (7)

Linear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmLinear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithm
 
Binary Search Tree for design and analysis
Binary Search Tree for design and analysisBinary Search Tree for design and analysis
Binary Search Tree for design and analysis
 
Software Engineering Book for beginnerss
Software Engineering Book for beginnerssSoftware Engineering Book for beginnerss
Software Engineering Book for beginnerss
 
Software tetsing paper related to industry
Software tetsing paper related to industrySoftware tetsing paper related to industry
Software tetsing paper related to industry
 
Week 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learningWeek 1 Lecture 1 LAB Weka lecture for machine learning
Week 1 Lecture 1 LAB Weka lecture for machine learning
 
lecture_for programming and computing basics
lecture_for programming and computing basicslecture_for programming and computing basics
lecture_for programming and computing basics
 
chapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineeringchapter_3_8 of software requirements engineering
chapter_3_8 of software requirements engineering
 

Recently uploaded

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 

Greedy algorithm for design and analysis

  • 2. Optimization and Optimal value • Any problem which could be solved using more than one way is called an optimization problem. For instance, we travel from one point to another and we have more than one routes. • When we reach to our destination at a lowest possible cost, it is the optimal value.
  • 3. Commonly used optimization algorithms • Greedy Algorithm • Dynamic Programming
  • 4. Greedy Algorithm • Before explaining it, lets see a scenario.
  • 5. • Since she has no pockets in her trouser, she needs coins as less as possible. • The problem to be solved here is to give her 85 dollars with less possible coins.
  • 6. Available coins with Alex Options are: • Bags full of 50, 20, 10 and 5 dollars coins only
  • 7. What are available options • We have all these possible options + more
  • 8. Optimal value at each step • Greedy algorithm selects the minimum or maximum (in this case) at each step.
  • 9. What is Greedy Algorithm • It is an optimization problem-solving method which selects the locally optimal (i.e. maximum or minimum in the available) choice at each step and hope it achieve the global optimum. • Greedy Algorithms work step-by-step, and always choose the steps which provide immediate profit/benefit. • It chooses the “locally optimal solution”, without thinking about future consequences.
  • 10. What is Greedy Algorithm • Greedy algorithms may not always lead to the optimal global solution, because it does not consider the entire data. • The choice made by the greedy approach does not consider future data and choices. • In some cases making a decision that looks right at that moment gives the best solution (Greedy), but in other cases, it doesn’t.
  • 12. Do Greedy Algorithm always find global optimal? No
  • 13. Dynamic Programming • Most of the optimization algorithms (e.g. Greedy) work on simple princple; solve the components of the main problem (i.e. subproblem), combine these sub-solutions and get to an overall solution. • Many subproblems are created and solved repeatedly . To reduce the number of computations, the Dynamic Programming approach aims to answer each subproblem just once. • Once the solution to a given subproblem has been computed, it is saved or "memoized," making it easy to find the next time the exact solution is required.
  • 14. Dynamic Programming • In daily life, we are using the aproach of dynamic programming but we dont notice it. • We ask a kid to count the sticks, he counts and correctly answer of “4”
  • 15. We actually applied dynamic programming • We add another stick and ask again, he doesn’t count it again and still says the answer as 5. • The kid memorize the previous answer and hence, no need to count it again.
  • 16. 1. Optimal substructures • If the overall optimal solution of a problem can be determined from the optimal solutions of its subproblems, this is referred to as having an optimal substructure property. • We are aware that the nth Fibonacci number, or Fib(n), is nothing more than the sum of the two preceding Fibonacci numbers, or Fib(n) = Fib(n-1) + Fib (n-2). • A problem of size 'n' has been divided into subproblems of sizes 'n-1' and 'n-2,' as shown by the equation above.
  • 17. 2. Overlapping Subproblems • If addressing the same subproblem occur more than once , that subproblem is said to have overlapping subproblems.
  • 18. An example of Fibonacci numbers • Let's think about analyzing Fib (5). We can see that Fib(5) is calculated by taking the sum of Fib(4) and Fib(3), and Fib(4) is calculated by taking the sum of Fib(3) and Fib(2), and so on. • Fib(3), Fib(2), Fib(1), and Fib(0) have all undergone repeated evaluation. These are nothing more than converging sub- Problems.
  • 19. Greedy vs Dynamic Programming Greedy • No guarantee of getting optimal solution • Efficient in terms of memory. • Fast algorithm Dynamic Programming • Optimal solution is guaranteed as it generally considers all possible cases and then choose the best. • It stores previous results, so consumes memory. • Comparatively slow