SlideShare a Scribd company logo
Presented By:
Minhaz Uddin
ID: 151001612
Greedy algorithm Definition:
A greedy algorithm always makes the choice that seems
to be the best at that moment. So it makes a locally
optimal choice in the hope that this choice will lead to a
globally optimal solution.
GreedyAlgorithm : Dijkstra's Algorithm
Step:
1.Set all vertices distances equal to infinity without for
the source vertex, set the source distance equal zero.
2.Push the source vertex in a min-priority queue in the
form as the comparison in the min-priority queue will
be according to vertices distances.
3.Pop the vertex with the minimum distance from the
priority queue .
4.Update the distances of the connected vertices to the
popped vertex in case of
"current vertex distance + edge weight < next vertex
distance", then push the vertex with the new distance to
the priority queue.
5.If the popped vertex is visited before, just continue
without using it.
6.Apply the same algorithm again until the priority
queue is empty.
Dijkstra's Example:
2
B C
5 1 3
A D
8
Dijkstra's Example:
2
∞ B C ∞
5 1 3
0 A D ∞
8
Dijkstra's Example:
Start from A because A distance equal zero.
2
5 B C ∞
5 3
0 A D 8
8
Now A to B (0+5)< ∞ So B distance =5
Now A to D (0+8)< ∞ So D distance = 8
Output : A
Dijkstra's Example:
New start point B because B distance (5) < D distance
(8)
5 B 2 C 7
5 1 3
0 A D 8
8
Now B to A is not needed because A already visited
Now B to C (5+2)< ∞ So C distance = 7
Output : A B
Dijkstra's Example:
New start point C
5 B 2 C 7
5 3
0 A D 10
8
Now C to B is not needed because B already
visited
Now C to D (7+3)< ∞ So D distance = 10
Output : A B C
Dijkstra's Example:
New start point D
5 B 2 C 7
5 3
0 A D 10
8
No unvisited edges are present.
So the work is done.
Output : A B C D

More Related Content

PDF
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
PDF
Implementation of dijsktra’s algorithm in parallel
PPTX
Csci101 lect09 vectorized_code
PPTX
Lecture two
PDF
5 octave tutorial
PPTX
FDM Numerical solution of Laplace Equation using MATLAB
PPTX
Lecture one
PPTX
My presentation minimum spanning tree
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
Implementation of dijsktra’s algorithm in parallel
Csci101 lect09 vectorized_code
Lecture two
5 octave tutorial
FDM Numerical solution of Laplace Equation using MATLAB
Lecture one
My presentation minimum spanning tree

What's hot (20)

PPTX
Shortest route and mst
PPTX
Lecture three
PPTX
PDF
Romberg’s method
PPTX
Secant method
PPTX
Check sum
PDF
12 support vector machines
PDF
9 neural network learning
PDF
14 dimentionality reduction
PDF
13 unsupervised learning clustering
PPT
Secant Method
PPTX
Analysing simple pendulum using matlab
PPT
09 numerical integration
PDF
Solution of matlab chapter 6
PPTX
Signal Processing Assignment Help
PPT
Minimum spanning tree
PDF
4 linear regeression with multiple variables
PDF
SKuehn_MachineLearningAndOptimization_2015
PPTX
Fourier Transform Assignment Help
PDF
Basic Fresher Algorithm
Shortest route and mst
Lecture three
Romberg’s method
Secant method
Check sum
12 support vector machines
9 neural network learning
14 dimentionality reduction
13 unsupervised learning clustering
Secant Method
Analysing simple pendulum using matlab
09 numerical integration
Solution of matlab chapter 6
Signal Processing Assignment Help
Minimum spanning tree
4 linear regeression with multiple variables
SKuehn_MachineLearningAndOptimization_2015
Fourier Transform Assignment Help
Basic Fresher Algorithm
Ad

Similar to Greedy (20)

PPTX
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
PPT
12 routing
PDF
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
PPTX
Shortest path algorithm
PPTX
Dijkstra’s algorithm
PPTX
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
PPT
Dijkstra c
PPTX
dms slide discrete mathematics sem 2 engineering
PPT
routing1 1X3 Router (capable of routing the data packets.ppt
PPTX
5.2_video_slides.pptx
PPTX
12_Graph.pptx
PPT
2.3 shortest path dijkstra’s
PPTX
Single source Shortest path algorithm with example
PPT
Unit26 shortest pathalgorithm
PDF
Lecture 16 - Dijkstra's Algorithm.pdf
PPTX
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
PPTX
Dijkstra's algorithm presentation
PPTX
Algo labpresentation a_group
PPT
barrera.ppt
PPT
barrera.ppt
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
12 routing
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
Shortest path algorithm
Dijkstra’s algorithm
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
Dijkstra c
dms slide discrete mathematics sem 2 engineering
routing1 1X3 Router (capable of routing the data packets.ppt
5.2_video_slides.pptx
12_Graph.pptx
2.3 shortest path dijkstra’s
Single source Shortest path algorithm with example
Unit26 shortest pathalgorithm
Lecture 16 - Dijkstra's Algorithm.pdf
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
Dijkstra's algorithm presentation
Algo labpresentation a_group
barrera.ppt
barrera.ppt
Ad

Recently uploaded (20)

PPTX
communication and presentation skills 01
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
introduction to high performance computing
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Abrasive, erosive and cavitation wear.pdf
PPT
Occupational Health and Safety Management System
PPTX
UNIT 4 Total Quality Management .pptx
PDF
737-MAX_SRG.pdf student reference guides
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPTX
UNIT - 3 Total quality Management .pptx
communication and presentation skills 01
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
R24 SURVEYING LAB MANUAL for civil enggi
Exploratory_Data_Analysis_Fundamentals.pdf
III.4.1.2_The_Space_Environment.p pdffdf
introduction to high performance computing
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Visual Aids for Exploratory Data Analysis.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Abrasive, erosive and cavitation wear.pdf
Occupational Health and Safety Management System
UNIT 4 Total Quality Management .pptx
737-MAX_SRG.pdf student reference guides
Categorization of Factors Affecting Classification Algorithms Selection
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Fundamentals of safety and accident prevention -final (1).pptx
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
UNIT - 3 Total quality Management .pptx

Greedy

  • 2. Greedy algorithm Definition: A greedy algorithm always makes the choice that seems to be the best at that moment. So it makes a locally optimal choice in the hope that this choice will lead to a globally optimal solution. GreedyAlgorithm : Dijkstra's Algorithm Step: 1.Set all vertices distances equal to infinity without for the source vertex, set the source distance equal zero. 2.Push the source vertex in a min-priority queue in the form as the comparison in the min-priority queue will be according to vertices distances.
  • 3. 3.Pop the vertex with the minimum distance from the priority queue . 4.Update the distances of the connected vertices to the popped vertex in case of "current vertex distance + edge weight < next vertex distance", then push the vertex with the new distance to the priority queue. 5.If the popped vertex is visited before, just continue without using it. 6.Apply the same algorithm again until the priority queue is empty.
  • 5. Dijkstra's Example: 2 ∞ B C ∞ 5 1 3 0 A D ∞ 8
  • 6. Dijkstra's Example: Start from A because A distance equal zero. 2 5 B C ∞ 5 3 0 A D 8 8 Now A to B (0+5)< ∞ So B distance =5 Now A to D (0+8)< ∞ So D distance = 8 Output : A
  • 7. Dijkstra's Example: New start point B because B distance (5) < D distance (8) 5 B 2 C 7 5 1 3 0 A D 8 8 Now B to A is not needed because A already visited Now B to C (5+2)< ∞ So C distance = 7 Output : A B
  • 8. Dijkstra's Example: New start point C 5 B 2 C 7 5 3 0 A D 10 8 Now C to B is not needed because B already visited Now C to D (7+3)< ∞ So D distance = 10 Output : A B C
  • 9. Dijkstra's Example: New start point D 5 B 2 C 7 5 3 0 A D 10 8 No unvisited edges are present. So the work is done. Output : A B C D