SlideShare a Scribd company logo
1 of 3
Ray Anthony Saavedra

ArrizPaul San Juan

IT2A

THE PROBLEM: SINGLE-SOURCE SHORTEST PATH (SSSP)

        In graph theory, the shortest path problem is the problem of finding a path between
two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is
minimized. An example is finding the quickest way to get from one location to another on a road
map; in this case, the vertices represent locations and the edges represent segments of road and
are weighted by the time needed to travel that segment. The problem is also sometimes called the
single-pair shortest path problem. It is used to find the shortest paths from a source vertex v to all
other vertices in the graph.




       THE PRACTICAL APPLICATIONS:

       1.) Finding the shortest path from your house to your school
       2.) If you want to deliver something, you can use it to find the shortest path to your
           destination
       3.) Finding the cheapest fare from one place to another
       4.) Finding the best route to avoid traffic in the streets.
THE SOLUTION: BELLMAN-FORD ALGORITHM



The Bellman–Ford algorithm computes single-source shortest paths in a weighted graph.
Bellman–Ford is used primarily for graphs with negative edge weights. The algorithm is named
after its developers, Richard Bellman and Lester Ford, Jr. If a graph contains a "negative cycle",
i.e., a cycle whose edges sum to a negative value, then walks of arbitrarily low weight can be
constructed, i.e., there may be no shortest path. Bellman-Ford can detect negative cycles and
report their existence, but it cannot produce a correct answer if a negative cycle is not reachable
from the source. The Bellman-Ford algorithm detects negative weight cycles and if it detects a
negative weight cycle on the graph, then Bellman-Ford will not able to find the shortest path. It
will not able to find the shortest path because if it keeps going around the negative cycle then we
are decreasing the weight in the path so it results to –infinity as the shortest path.




Algorithm:

           The Bellman-Ford algorithm is one of the classic solutions to this problem. It
           calculates the shortest path to all nodes in the graph from a single source.

   1.) Start by considering that the shortest path to all nodes, less the source, is infinity. Mark
       the length of the path to the source as 0.
2.) Take every edge and try to relax it. Relaxing an edge means checking to see if the path to
        the node the edge is pointing to can’t be shortened, and if so, doing it. In the above graph,
        by checking the edge 1 -> 2 of length 6, you find that the length of the shortest path
        to node 1 plus the length of the edge 1 -> 2 is less then infinity. So, you replace infinity
        in node 2 with 6. The same can be said for edge 1 -> 4 of length 7. It’s also worth noting
        that, practically, you can’t relax the edges whose start has the shortest path of length
        infinity to it.




    3.) Finally, it checks for negative weight cycles on the graph. It returns TRUE if there are no
        negative cycles that are reachable from source vertex and FALSE otherwise.




1




1
 Bellman-Ford Algorithm.Wikipedia. Retrieved March 8,2012. From
http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm

One Source Shortest Path: The Bellman-Ford Algorithm Retrieved March 8,2012.
Fromhttp://compprog.wordpress.com/2007/11/29/one-source-shortest-path-the-bellman-ford-algorithm/

More Related Content

Viewers also liked

T&D relation to cutting bed thickness
T&D relation to cutting bed thicknessT&D relation to cutting bed thickness
T&D relation to cutting bed thickness
Nikhil Barshettiwar
 
URS presentation (final)
URS presentation (final)URS presentation (final)
URS presentation (final)
sisi hu
 
Assignment short film 1 minute proposal, report planning and shoot
Assignment short film 1 minute proposal, report planning and shootAssignment short film 1 minute proposal, report planning and shoot
Assignment short film 1 minute proposal, report planning and shoot
ctkmedia
 

Viewers also liked (16)

Creencias
CreenciasCreencias
Creencias
 
Bab i
Bab iBab i
Bab i
 
θρησκευτικά Pp
θρησκευτικά Ppθρησκευτικά Pp
θρησκευτικά Pp
 
Northern Nevada Off Road Safety Seminar
Northern Nevada Off Road Safety SeminarNorthern Nevada Off Road Safety Seminar
Northern Nevada Off Road Safety Seminar
 
5 3,4 lyduna
5 3,4 lyduna5 3,4 lyduna
5 3,4 lyduna
 
Ensamble del pc del laboratorio
Ensamble del pc del laboratorioEnsamble del pc del laboratorio
Ensamble del pc del laboratorio
 
Mecanografía
Mecanografía Mecanografía
Mecanografía
 
Making Beautiful Music : Nasig 2012 final
Making Beautiful Music : Nasig 2012 finalMaking Beautiful Music : Nasig 2012 final
Making Beautiful Music : Nasig 2012 final
 
Preliminary Task Evaluation
Preliminary Task EvaluationPreliminary Task Evaluation
Preliminary Task Evaluation
 
T&D relation to cutting bed thickness
T&D relation to cutting bed thicknessT&D relation to cutting bed thickness
T&D relation to cutting bed thickness
 
URS presentation (final)
URS presentation (final)URS presentation (final)
URS presentation (final)
 
Assignment short film 1 minute proposal, report planning and shoot
Assignment short film 1 minute proposal, report planning and shootAssignment short film 1 minute proposal, report planning and shoot
Assignment short film 1 minute proposal, report planning and shoot
 
Trus biopsy prostate
Trus biopsy prostateTrus biopsy prostate
Trus biopsy prostate
 
Customer Lifecycle Engagement for Insurance Companies
Customer Lifecycle Engagement for Insurance CompaniesCustomer Lifecycle Engagement for Insurance Companies
Customer Lifecycle Engagement for Insurance Companies
 
Christian symbols
Christian symbolsChristian symbols
Christian symbols
 
Campana Teka CNL1 3000
Campana Teka CNL1 3000 Campana Teka CNL1 3000
Campana Teka CNL1 3000
 

Similar to Algo

shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
zefergaming
 
MDM-Chapter-9-Updated latest.pptx
MDM-Chapter-9-Updated latest.pptxMDM-Chapter-9-Updated latest.pptx
MDM-Chapter-9-Updated latest.pptx
JimSotio
 

Similar to Algo (20)

The Floyd–Warshall algorithm
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithm
 
shortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdfshortestpathalgorithm-180109112405 (1).pdf
shortestpathalgorithm-180109112405 (1).pdf
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
 
Ds presentation
Ds presentationDs presentation
Ds presentation
 
Presentation on BFS & Bellman Ford.pptx
Presentation on BFS & Bellman Ford.pptxPresentation on BFS & Bellman Ford.pptx
Presentation on BFS & Bellman Ford.pptx
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraq
 
Shortest Path Algorithm
Shortest Path AlgorithmShortest Path Algorithm
Shortest Path Algorithm
 
Graph 3
Graph 3Graph 3
Graph 3
 
Hamilton paths and circuit
Hamilton paths and circuitHamilton paths and circuit
Hamilton paths and circuit
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
 
The Traveling Salesman problem ppt.pptx
The Traveling Salesman problem ppt.pptxThe Traveling Salesman problem ppt.pptx
The Traveling Salesman problem ppt.pptx
 
path
pathpath
path
 
E017512630
E017512630E017512630
E017512630
 
S210
S210S210
S210
 
Spsp fw
Spsp fwSpsp fw
Spsp fw
 
06_AJMS_334_21.pdf
06_AJMS_334_21.pdf06_AJMS_334_21.pdf
06_AJMS_334_21.pdf
 
DAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptx
 
MDM-Chapter-9-Updated latest.pptx
MDM-Chapter-9-Updated latest.pptxMDM-Chapter-9-Updated latest.pptx
MDM-Chapter-9-Updated latest.pptx
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Algo

  • 1. Ray Anthony Saavedra ArrizPaul San Juan IT2A THE PROBLEM: SINGLE-SOURCE SHORTEST PATH (SSSP) In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. An example is finding the quickest way to get from one location to another on a road map; in this case, the vertices represent locations and the edges represent segments of road and are weighted by the time needed to travel that segment. The problem is also sometimes called the single-pair shortest path problem. It is used to find the shortest paths from a source vertex v to all other vertices in the graph. THE PRACTICAL APPLICATIONS: 1.) Finding the shortest path from your house to your school 2.) If you want to deliver something, you can use it to find the shortest path to your destination 3.) Finding the cheapest fare from one place to another 4.) Finding the best route to avoid traffic in the streets.
  • 2. THE SOLUTION: BELLMAN-FORD ALGORITHM The Bellman–Ford algorithm computes single-source shortest paths in a weighted graph. Bellman–Ford is used primarily for graphs with negative edge weights. The algorithm is named after its developers, Richard Bellman and Lester Ford, Jr. If a graph contains a "negative cycle", i.e., a cycle whose edges sum to a negative value, then walks of arbitrarily low weight can be constructed, i.e., there may be no shortest path. Bellman-Ford can detect negative cycles and report their existence, but it cannot produce a correct answer if a negative cycle is not reachable from the source. The Bellman-Ford algorithm detects negative weight cycles and if it detects a negative weight cycle on the graph, then Bellman-Ford will not able to find the shortest path. It will not able to find the shortest path because if it keeps going around the negative cycle then we are decreasing the weight in the path so it results to –infinity as the shortest path. Algorithm: The Bellman-Ford algorithm is one of the classic solutions to this problem. It calculates the shortest path to all nodes in the graph from a single source. 1.) Start by considering that the shortest path to all nodes, less the source, is infinity. Mark the length of the path to the source as 0.
  • 3. 2.) Take every edge and try to relax it. Relaxing an edge means checking to see if the path to the node the edge is pointing to can’t be shortened, and if so, doing it. In the above graph, by checking the edge 1 -> 2 of length 6, you find that the length of the shortest path to node 1 plus the length of the edge 1 -> 2 is less then infinity. So, you replace infinity in node 2 with 6. The same can be said for edge 1 -> 4 of length 7. It’s also worth noting that, practically, you can’t relax the edges whose start has the shortest path of length infinity to it. 3.) Finally, it checks for negative weight cycles on the graph. It returns TRUE if there are no negative cycles that are reachable from source vertex and FALSE otherwise. 1 1 Bellman-Ford Algorithm.Wikipedia. Retrieved March 8,2012. From http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm One Source Shortest Path: The Bellman-Ford Algorithm Retrieved March 8,2012. Fromhttp://compprog.wordpress.com/2007/11/29/one-source-shortest-path-the-bellman-ford-algorithm/