SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Tendances (20)

Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common Subsequence
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
NP completeness
NP completenessNP completeness
NP completeness
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Backtracking
BacktrackingBacktracking
Backtracking
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Randomized Algorithm
Randomized AlgorithmRandomized Algorithm
Randomized Algorithm
 
Backtracking Algorithm.ppt
Backtracking Algorithm.pptBacktracking Algorithm.ppt
Backtracking Algorithm.ppt
 
The Traveling Salesman Problem
The Traveling Salesman ProblemThe Traveling Salesman Problem
The Traveling Salesman Problem
 
Lecture28 tsp
Lecture28 tspLecture28 tsp
Lecture28 tsp
 
Dijkstra’S Algorithm
Dijkstra’S AlgorithmDijkstra’S Algorithm
Dijkstra’S Algorithm
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 

En vedette

Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy methodTech_MX
 
program pencarian data dengan bahasa C
program pencarian data dengan bahasa Cprogram pencarian data dengan bahasa C
program pencarian data dengan bahasa Ckir yy
 
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 variabelradar radius
 
Big o notation
Big o notationBig o notation
Big o notationkeb97
 
Business Transformation 1
Business Transformation 1Business Transformation 1
Business Transformation 1ss
 

En vedette (6)

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
 
Big o notation
Big o notationBig o notation
Big o notation
 
Business Transformation 1
Business Transformation 1Business Transformation 1
Business Transformation 1
 

Plus de Caisar Oentoro

Plus 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
 

Dernier

COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 

Dernier (20)

COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 

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