SlideShare una empresa de Scribd logo
1 de 10
Short Explanation, Caisar Oentoro
What is Greedy Algorithm?
 In the hard words: A greedy algorithm is
  an algorithm that follows the problem solving
  heuristics of making the locally optimal choice at each
  stage with the hope of finding a global optimum.
  (src: http://en.wikipedia.org/wiki/Greedy_algorithm)
 Simplify: Choose the best choice that ‘reachable’ at
  current state
Sample Usage of Greedy
 For better explanation we use old simple problem:
 Travelling Salesman Problem:
TSP
 The Problem is how to travel from city A and visit all
  city on the map, then back to city A again.




 The rules: you only visit each city once and you can’t
  pass through any traversed path.
Solution:
 Find the shortest path from city A(start) to any other
  city.
                                 A               B




 Because the nearest city is B, so we go to B
 From B, we find any other city but A(because A has
 been visited) that has nearest path. So we choose C:


                               A               B




                               C




Keep tuning on…
 From C, we look to nearest city again, but don’t look
 for A and B, because both has been visited. So we
 choose D.

                                A               B




                                C               D



Soon end…
 At this node(D), we can’t go to any city, because all
  neighbor of D has been visited. We go back to first
  city(A).
                                 A                B




                                 C                D



 And that was how to solve TSP problem.
Advantage of Greedy
 Greedy is easy to be implemented. Just search the best
  choice from the current state that ‘reachable’ (has any
  paths or any connections).
 In simple case, greedy often give you the best solution.
Drawback of Greedy
 In large and complex case, greedy doesn’t always give
  you the best solution, because it’s just search and take
  the best choice that you can reach from the current
  state.
 It takes longer time than any other algorithms for big
  case of problem

Más contenido relacionado

La actualidad más candente

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 

La actualidad más candente (20)

Travelling SalesMan Problem(TSP)
Travelling SalesMan Problem(TSP)Travelling SalesMan Problem(TSP)
Travelling SalesMan Problem(TSP)
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
AI_Session 8 A searching algorithm .pptx
AI_Session 8 A searching algorithm .pptxAI_Session 8 A searching algorithm .pptx
AI_Session 8 A searching algorithm .pptx
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Lecture 26 local beam search
Lecture 26 local beam searchLecture 26 local beam search
Lecture 26 local beam search
 
Heuristic search
Heuristic searchHeuristic search
Heuristic search
 
implementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptimplementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity ppt
 
A Star Search
A Star SearchA Star Search
A Star Search
 
Activity selection problem
Activity selection problemActivity selection problem
Activity selection problem
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
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
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
 
Heuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.pptHeuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.ppt
 
Problem solving agents
Problem solving agentsProblem solving agents
Problem solving agents
 

Destacado (8)

Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy method
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
program pencarian data dengan bahasa C
program pencarian data dengan bahasa Cprogram pencarian data dengan bahasa C
program pencarian data dengan bahasa C
 
Materi 4 penyelesaian spl tiga atau lebih variabel
Materi 4 penyelesaian spl tiga atau lebih variabelMateri 4 penyelesaian spl tiga atau lebih variabel
Materi 4 penyelesaian spl tiga atau lebih variabel
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
 
Big o notation
Big o notationBig o notation
Big o notation
 
Business Transformation 1
Business Transformation 1Business Transformation 1
Business Transformation 1
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 

Más de Caisar Oentoro (8)

D3.JS Data-Driven Documents
D3.JS Data-Driven DocumentsD3.JS Data-Driven Documents
D3.JS Data-Driven Documents
 
Android forensik 2
Android forensik 2Android forensik 2
Android forensik 2
 
Android forensik 1
Android forensik 1Android forensik 1
Android forensik 1
 
Android forensik 4
Android forensik 4Android forensik 4
Android forensik 4
 
Android forensik
Android forensikAndroid forensik
Android forensik
 
Mini magazine
Mini magazineMini magazine
Mini magazine
 
Metode SMART
Metode SMARTMetode SMART
Metode SMART
 
How Reflex Works
How Reflex WorksHow Reflex Works
How Reflex Works
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Greedy algorithm

  • 2. What is Greedy Algorithm?  In the hard words: A greedy algorithm is an algorithm that follows the problem solving heuristics of making the locally optimal choice at each stage with the hope of finding a global optimum. (src: http://en.wikipedia.org/wiki/Greedy_algorithm)  Simplify: Choose the best choice that ‘reachable’ at current state
  • 3. Sample Usage of Greedy  For better explanation we use old simple problem: Travelling Salesman Problem:
  • 4. TSP  The Problem is how to travel from city A and visit all city on the map, then back to city A again.  The rules: you only visit each city once and you can’t pass through any traversed path.
  • 5. Solution:  Find the shortest path from city A(start) to any other city. A B  Because the nearest city is B, so we go to B
  • 6.  From B, we find any other city but A(because A has been visited) that has nearest path. So we choose C: A B C Keep tuning on…
  • 7.  From C, we look to nearest city again, but don’t look for A and B, because both has been visited. So we choose D. A B C D Soon end…
  • 8.  At this node(D), we can’t go to any city, because all neighbor of D has been visited. We go back to first city(A). A B C D  And that was how to solve TSP problem.
  • 9. Advantage of Greedy  Greedy is easy to be implemented. Just search the best choice from the current state that ‘reachable’ (has any paths or any connections).  In simple case, greedy often give you the best solution.
  • 10. Drawback of Greedy  In large and complex case, greedy doesn’t always give you the best solution, because it’s just search and take the best choice that you can reach from the current state.  It takes longer time than any other algorithms for big case of problem