SlideShare a Scribd company logo
Presented By:
Hafiz Muhammad Amjad
Safi Ullah Nasir
Rimsha Riaz
1
Outline
Introduction
Optimization Problem
Characteristics And Features
Greedy Properties.
Greedy Approach
The Coin Changing Problem.
Traveling Salesman.
MST
Kruskal’s And Prim’s Algorithm.
Huffman Code.
Advantages And Disadvantages
2
Greedy Introduction
Greedy algorithms are simple and straightforward.
They are shortsighted in their approach
A greedy algorithm is similar to a dynamic
programming algorithm, but the difference is that
solutions to the sub problems do not have to be known
at each stage
It is used to solve the optimization problems.
3
Optimization Problems
An optimization problem is one in which you want to find,
not just a solution, but the best solution
A “greedy algorithm” sometimes works well for
optimization problems
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
4
Characteristics And Features
To construct the solution in an optimal way.
Algorithm Maintains two sets
One contains chosen items and
The other contains rejected items.
Greedy algorithms make good local choices in the
hope that They result in
An optimal solution.
Feasible solutions.
5
Greedy Property
It consists of two property.
1. Greedy-Choice Property:
It says that a globally optimal solution can be arrived at by
making a locally optimal choice.
2. Optimal Substructure:
An optimal global solution contains the optimal solutions
of all its sub problems.
6
Greedy Approach
Greedy Algorithm works by making the decision that seems
most promising at any moment; it never reconsiders this
decision, whatever situation may arise later.
As an example consider the problem of "Making Change".
Coins available are:
100 cents
25 cents
10 cents
15 cents
1 cent
7
CONTINUED…
Problem:
Make a change of a given amount using the smallest possible
number of coins.
Solution:
The coin is selected using greedy criterion: at each stage
increases the total amount of change constructed as much as
possible.
To assure feasibility i.e. the change given exactly equals the
desired amount of the solution
8
Coin Changing Problem
Algorithm:
Make change for n units using the least possible number of coins.
MAKE-CHANGE (n)
C ← {100, 25, 10, 15, 1} // constant.
S← {}; // set that will hold the solution set.
Sum ← 0 sum of item in solution set
WHILE sum not = n
x = largest item in set C such that sum + x ≤ n
IF no such item THEN
RETURN "No Solution"
S ← S {value of x} & Remove x from C.
sum ← sum + x
RETURN S
9
Traveling Salesman
A salesman must visit every city (starting from city A), and
wants to cover the least possible distance
He can revisit a city (and reuse a road) if necessary
He does this by using a greedy algorithm: He goes to the next
nearest city from wherever he is
From A he goes to B
From B he goes to D
This is not going to result in a
shortest path!
The best result he can get now
will be ABDBCE, at a cost of 16
An actual least-cost path from A
is ADBCE, at a cost of 14
10
E
A B C
D
2
3 3
4
4 4
An Example Of MST
A graph and one of its minimum costs spanning tree.
Application of MST.
4 -11
Kruskal’s Algorithm For
Finding MST
Step 1: Sort all edges into non decreasing order.
Step 2: Add the next smallest weight edge to the forest if it will
not cause a cycle.
Step 3: Stop if n-1 edges. Otherwise, go to Step2.
4 -12
An Example Of Kruskal’s Algorithm
4 -13
Prim’s Algorithm For Finding
MST
Initialize a tree with a single vertex, chosen
arbitrarily from the graph.
Grow the tree by one edge: of the edges that
connect the tree to vertices not yet in the tree,
find the minimum-weight edge, and transfer
it to the tree.
Repeat step 2 (until all vertices are in the
tree).And E=V-1.
4 -14
An Example For Prim’s Algorithm
4 -15
Huffman Encoding
The Huffman encoding algorithm is a greedy algorithm
You always pick the two smallest numbers to combine
The Huffman
algorithm finds an
optimal solution
16
22 12 24 6 27 9
A B C D E F
15
27
46
54
100
A=00
B=100
C=01
D=1010
E=11
F=1011
0
1
0 1
0
1
0
1
0 1
Advantages And Disadvantages
Advantages:
They are easier to implement.
They require much less computing resources.
They are much faster to execute.
Greedy algorithms are used to solve optimization
problems
Disadvantages:
Their only disadvantage being that they not always reach
the global optimum solution.
 On the other hand, even when the global optimum
solution is not reached, most of the times the reached sub-
optimal solution is a very good solution.
17
18

More Related Content

What's hot

Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
Subid Biswas
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
sana younas
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Dr Shashikant Athawale
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
Dr Geetha Mohan
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
Megha Sharma
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
smruti sarangi
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsing
sanchi29
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
Saurabh Kumar
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
SOMNATHMORE2
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
Mohammad Imam Hossain
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 

What's hot (20)

Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Dijkstra's algorithm presentation
Dijkstra's algorithm presentationDijkstra's algorithm presentation
Dijkstra's algorithm presentation
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsing
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 

Viewers also liked

Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
Caisar Oentoro
 
Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy methodTech_MX
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.com
Hemant Gautam
 
Class warshal2
Class warshal2Class warshal2
Class warshal2
Debarati Das
 
Knapsack
KnapsackKnapsack
Knapsack
Karthik Chetla
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programmingparamalways
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Freeing India of “Divide & Rule”
Freeing India of “Divide & Rule” Freeing India of “Divide & Rule”
Freeing India of “Divide & Rule”
cvikash
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11Kumar
 
Application of greedy method prim
Application of greedy method primApplication of greedy method prim
Application of greedy method primTech_MX
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
Vikas Sharma
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
Kàŕtheek Jåvvàjí
 
Greedy Knapsack Problem - by Y Achchuthan
Greedy Knapsack Problem  - by Y AchchuthanGreedy Knapsack Problem  - by Y Achchuthan
Greedy Knapsack Problem - by Y Achchuthan
Achchuthan Yogarajah
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
ishmecse13
 

Viewers also liked (20)

Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy method
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Greedy
GreedyGreedy
Greedy
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.com
 
Class warshal2
Class warshal2Class warshal2
Class warshal2
 
Knapsack
KnapsackKnapsack
Knapsack
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
 
Freeing India of “Divide & Rule”
Freeing India of “Divide & Rule” Freeing India of “Divide & Rule”
Freeing India of “Divide & Rule”
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11
 
Lec30
Lec30Lec30
Lec30
 
Application of greedy method prim
Application of greedy method primApplication of greedy method prim
Application of greedy method prim
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
 
Greedy Knapsack Problem - by Y Achchuthan
Greedy Knapsack Problem  - by Y AchchuthanGreedy Knapsack Problem  - by Y Achchuthan
Greedy Knapsack Problem - by Y Achchuthan
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
 

Similar to Greedy Algorihm

Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
22bcs058
 
Greedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computerGreedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computer
kerimu1235
 
Approximation algorithms
Approximation  algorithms Approximation  algorithms
Approximation algorithms
Bipesh Raj Subedi
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
Kislay Bhardwaj L|PT,ECSA,C|EH
 
Unit3_1.pdf
Unit3_1.pdfUnit3_1.pdf
Unit3_1.pdf
Pratimakumari213460
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
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
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
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
Jay Patel
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
B.Kirron Reddi
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
GOWTHAMR721887
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
TayyabSattar5
 
A greedy algorithms
A greedy algorithmsA greedy algorithms
A greedy algorithms
Amit Kumar Rathi
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
DynamicProgramming.pptx
DynamicProgramming.pptxDynamicProgramming.pptx
DynamicProgramming.pptx
SaimaShaheen14
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptx
MaryJacob24
 

Similar to Greedy Algorihm (20)

Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
 
Greedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computerGreedy algorithm pptxe file for computer
Greedy algorithm pptxe file for computer
 
Approximation algorithms
Approximation  algorithms Approximation  algorithms
Approximation algorithms
 
35 algorithm-types
35 algorithm-types35 algorithm-types
35 algorithm-types
 
Unit3_1.pdf
Unit3_1.pdfUnit3_1.pdf
Unit3_1.pdf
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation 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
 
32 algorithm-types
32 algorithm-types32 algorithm-types
32 algorithm-types
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
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
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
 
Data Analysis and Algorithms Lecture 1: Introduction
 Data Analysis and Algorithms Lecture 1: Introduction Data Analysis and Algorithms Lecture 1: Introduction
Data Analysis and Algorithms Lecture 1: Introduction
 
A greedy algorithms
A greedy algorithmsA greedy algorithms
A greedy algorithms
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
Approximation Algorithms TSP
 
36 greedy
36 greedy36 greedy
36 greedy
 
DynamicProgramming.pptx
DynamicProgramming.pptxDynamicProgramming.pptx
DynamicProgramming.pptx
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptx
 

More from Muhammad Amjad Rana

Applications Of Computer Graphics
Applications Of Computer GraphicsApplications Of Computer Graphics
Applications Of Computer Graphics
Muhammad Amjad Rana
 
IEEE Code Of Conduct/Ethics
IEEE Code Of Conduct/EthicsIEEE Code Of Conduct/Ethics
IEEE Code Of Conduct/Ethics
Muhammad Amjad Rana
 
Agile software development
Agile software developmentAgile software development
Agile software development
Muhammad Amjad Rana
 
Constitution Of 1973
Constitution Of 1973Constitution Of 1973
Constitution Of 1973
Muhammad Amjad Rana
 
OSI Model By Amjad, Rimsha Safi Ullah And Iqra
OSI Model By Amjad, Rimsha Safi Ullah And IqraOSI Model By Amjad, Rimsha Safi Ullah And Iqra
OSI Model By Amjad, Rimsha Safi Ullah And Iqra
Muhammad Amjad Rana
 
Superstitions By M Amjad, Rimsha Riaz And Faiqa
Superstitions By M Amjad, Rimsha Riaz And FaiqaSuperstitions By M Amjad, Rimsha Riaz And Faiqa
Superstitions By M Amjad, Rimsha Riaz And Faiqa
Muhammad Amjad Rana
 

More from Muhammad Amjad Rana (10)

Applications Of Computer Graphics
Applications Of Computer GraphicsApplications Of Computer Graphics
Applications Of Computer Graphics
 
IEEE Code Of Conduct/Ethics
IEEE Code Of Conduct/EthicsIEEE Code Of Conduct/Ethics
IEEE Code Of Conduct/Ethics
 
Big data
Big dataBig data
Big data
 
Agile software development
Agile software developmentAgile software development
Agile software development
 
Constitution Of 1973
Constitution Of 1973Constitution Of 1973
Constitution Of 1973
 
OSI Model By Amjad, Rimsha Safi Ullah And Iqra
OSI Model By Amjad, Rimsha Safi Ullah And IqraOSI Model By Amjad, Rimsha Safi Ullah And Iqra
OSI Model By Amjad, Rimsha Safi Ullah And Iqra
 
Superstitions By M Amjad, Rimsha Riaz And Faiqa
Superstitions By M Amjad, Rimsha Riaz And FaiqaSuperstitions By M Amjad, Rimsha Riaz And Faiqa
Superstitions By M Amjad, Rimsha Riaz And Faiqa
 
Microsoft BY AMJAD
Microsoft BY AMJADMicrosoft BY AMJAD
Microsoft BY AMJAD
 
Microsoft BY Amjad
Microsoft BY AmjadMicrosoft BY Amjad
Microsoft BY Amjad
 
Google By Amjad
Google By AmjadGoogle By Amjad
Google By Amjad
 

Recently uploaded

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)
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
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
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
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
 
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
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
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
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
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
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
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 ...
 
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
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
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.
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

Greedy Algorihm

  • 1. Presented By: Hafiz Muhammad Amjad Safi Ullah Nasir Rimsha Riaz 1
  • 2. Outline Introduction Optimization Problem Characteristics And Features Greedy Properties. Greedy Approach The Coin Changing Problem. Traveling Salesman. MST Kruskal’s And Prim’s Algorithm. Huffman Code. Advantages And Disadvantages 2
  • 3. Greedy Introduction Greedy algorithms are simple and straightforward. They are shortsighted in their approach A greedy algorithm is similar to a dynamic programming algorithm, but the difference is that solutions to the sub problems do not have to be known at each stage It is used to solve the optimization problems. 3
  • 4. Optimization Problems An optimization problem is one in which you want to find, not just a solution, but the best solution A “greedy algorithm” sometimes works well for optimization problems 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 4
  • 5. Characteristics And Features To construct the solution in an optimal way. Algorithm Maintains two sets One contains chosen items and The other contains rejected items. Greedy algorithms make good local choices in the hope that They result in An optimal solution. Feasible solutions. 5
  • 6. Greedy Property It consists of two property. 1. Greedy-Choice Property: It says that a globally optimal solution can be arrived at by making a locally optimal choice. 2. Optimal Substructure: An optimal global solution contains the optimal solutions of all its sub problems. 6
  • 7. Greedy Approach Greedy Algorithm works by making the decision that seems most promising at any moment; it never reconsiders this decision, whatever situation may arise later. As an example consider the problem of "Making Change". Coins available are: 100 cents 25 cents 10 cents 15 cents 1 cent 7
  • 8. CONTINUED… Problem: Make a change of a given amount using the smallest possible number of coins. Solution: The coin is selected using greedy criterion: at each stage increases the total amount of change constructed as much as possible. To assure feasibility i.e. the change given exactly equals the desired amount of the solution 8
  • 9. Coin Changing Problem Algorithm: Make change for n units using the least possible number of coins. MAKE-CHANGE (n) C ← {100, 25, 10, 15, 1} // constant. S← {}; // set that will hold the solution set. Sum ← 0 sum of item in solution set WHILE sum not = n x = largest item in set C such that sum + x ≤ n IF no such item THEN RETURN "No Solution" S ← S {value of x} & Remove x from C. sum ← sum + x RETURN S 9
  • 10. Traveling Salesman A salesman must visit every city (starting from city A), and wants to cover the least possible distance He can revisit a city (and reuse a road) if necessary He does this by using a greedy algorithm: He goes to the next nearest city from wherever he is From A he goes to B From B he goes to D This is not going to result in a shortest path! The best result he can get now will be ABDBCE, at a cost of 16 An actual least-cost path from A is ADBCE, at a cost of 14 10 E A B C D 2 3 3 4 4 4
  • 11. An Example Of MST A graph and one of its minimum costs spanning tree. Application of MST. 4 -11
  • 12. Kruskal’s Algorithm For Finding MST Step 1: Sort all edges into non decreasing order. Step 2: Add the next smallest weight edge to the forest if it will not cause a cycle. Step 3: Stop if n-1 edges. Otherwise, go to Step2. 4 -12
  • 13. An Example Of Kruskal’s Algorithm 4 -13
  • 14. Prim’s Algorithm For Finding MST Initialize a tree with a single vertex, chosen arbitrarily from the graph. Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and transfer it to the tree. Repeat step 2 (until all vertices are in the tree).And E=V-1. 4 -14
  • 15. An Example For Prim’s Algorithm 4 -15
  • 16. Huffman Encoding The Huffman encoding algorithm is a greedy algorithm You always pick the two smallest numbers to combine The Huffman algorithm finds an optimal solution 16 22 12 24 6 27 9 A B C D E F 15 27 46 54 100 A=00 B=100 C=01 D=1010 E=11 F=1011 0 1 0 1 0 1 0 1 0 1
  • 17. Advantages And Disadvantages Advantages: They are easier to implement. They require much less computing resources. They are much faster to execute. Greedy algorithms are used to solve optimization problems Disadvantages: Their only disadvantage being that they not always reach the global optimum solution.  On the other hand, even when the global optimum solution is not reached, most of the times the reached sub- optimal solution is a very good solution. 17
  • 18. 18