Shortest Path Problem: Difference between revisions

From Rice Wiki
No edit summary
No edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<syntaxhighlighting lang="python" line>
= Definitions =
def quick_sort(arr):
 
less = []
A path is a sequence of nodes <math> x_1, x_2, x_3, \ldots, x_i </math>such that for all consecutive nodes, there exist an edge
pivot_list = []
 
more = []
Let there be a weight assigned to each edge.
if len(arr) <= 1:
 
return arr
= Single Source Shortest Path (SSSP) =
else:
 
pass
Given a graph <math> G(V,E), w(e) </math>, source node <math> S </math>, output the shortest path from the source
</syntaxhighlighting>
 
== Variants ==
 
* Single destination problem: shortest path from all nodes to a single destination
* Single pair problem: Shortest path between input pair
 
= Suboptimality =
 
Given <math>OPT = x_1, x_2, \ldots</math> is the shortest path.
 
Prove that <math>A = OPT - x_1</math> is the shortest path between
<math>x_2</math> and the end.
 
For contradiction, assume <math>A</math> is not optimal. There must be
<math>B</math> such that
 
<math>w(B) < w(A)</math>
 
Adding the path back, it is clear that it doesn't work.
 
[[Category:Algorithms]]

Latest revision as of 01:32, 8 March 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 } , output 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

Suboptimality

Given 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 OPT = x_1, x_2, \ldots} is the shortest path.

Prove that 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 A = OPT - x_1} is the shortest path between 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_2} and the end.

For contradiction, assume 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 A} is not optimal. There must be 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 B} such that

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 w(B) < w(A)}

Adding the path back, it is clear that it doesn't work.