Shortest Path Problem: Difference between revisions
No edit summary |
No edit summary |
||
| Line 25: | Line 25: | ||
OPT(a, n-1) = min(w(u,a) + OPT(n-1, u)) | OPT(a, n-1) = min(w(u,a) + OPT(n-1, u)) | ||
</pre> | </pre> | ||
where | where | ||
<math> (u, a) \in E </math> | <math> (u, a) \in E </math> | ||
=== Bellman Ford Algorithm === | |||
<pre> | |||
for e = 1 to n - 1: | |||
for each u in V: | |||
OPT(u, e) = min(w(v,u) + OPT(v, e-1) for all (v, u)) | |||
OPT(u, e) = min(OPT(u,e), OPT(u, e-1)) | |||
</pre> | |||
Revision as of 01:47, 28 February 2024
Definitions
A path is a sequence of nodes Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle x_1, x_2, x_3, \ldots, x_i } such that for all consecutive nodes, there exist an edge
Let there be a weight assigned to each edge.
Single Source Shortest Path (SSSP)
Given a graph Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle G(V,E), w(e) } , source node Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle S } , outupt the shortest path from the source
Variants
- Single destination problem: shortest path from all nodes to a single destination
- Single pair problem: Shortest path between input pair
Implementation
All shortest path must have Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \leq n - 1 } edges. If this condition is not satisfied, there is a cycle in in the path, and therefore it is not the shortest.
OPT(a, n-1) = min(w(u,a) + OPT(n-1, u))
where
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (u, a) \in E }
Bellman Ford Algorithm
for e = 1 to n - 1:
for each u in V:
OPT(u, e) = min(w(v,u) + OPT(v, e-1) for all (v, u))
OPT(u, e) = min(OPT(u,e), OPT(u, e-1))
