<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wcipeg.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Johnson%27s_algorithm</id>
		<title>Johnson's algorithm - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wcipeg.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Johnson%27s_algorithm"/>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;action=history"/>
		<updated>2026-05-04T20:30:24Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.25.2</generator>

	<entry>
		<id>http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=2149&amp;oldid=prev</id>
		<title>172.68.10.246: fixed time of Dijkstra with Fibonacci heap</title>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=2149&amp;oldid=prev"/>
				<updated>2017-07-03T05:41:52Z</updated>
		
		<summary type="html">&lt;p&gt;fixed time of Dijkstra with Fibonacci heap&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 05:41, 3 July 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;L1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V) = O(V(E+V)\log V)&amp;lt;/math&amp;gt; using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;V&lt;/del&gt;\log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V) = O(V(E+V)\log V)&amp;lt;/math&amp;gt; using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + \log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>172.68.10.246</name></author>	</entry>

	<entry>
		<id>http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=2148&amp;oldid=prev</id>
		<title>172.68.10.246: fixed time of Dijkstra with Fibonacci heap</title>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=2148&amp;oldid=prev"/>
				<updated>2017-07-03T05:38:41Z</updated>
		
		<summary type="html">&lt;p&gt;fixed time of Dijkstra with Fibonacci heap&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 05:38, 3 July 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;L1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V) = O(V(E+V)\log V)&amp;lt;/math&amp;gt; using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + \log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V) = O(V(E+V)\log V)&amp;lt;/math&amp;gt; using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;V&lt;/ins&gt;\log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>172.68.10.246</name></author>	</entry>

	<entry>
		<id>http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1328&amp;oldid=prev</id>
		<title>Brian at 07:07, 26 May 2011</title>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1328&amp;oldid=prev"/>
				<updated>2011-05-26T07:07:03Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 07:07, 26 May 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;L1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V)&amp;lt;/math&amp;gt; using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + \log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;V(E+V)\log V) = O(&lt;/ins&gt;V(E+V)\log V)&amp;lt;/math&amp;gt; using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + \log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	<entry>
		<id>http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1327&amp;oldid=prev</id>
		<title>Brian at 07:04, 26 May 2011</title>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1327&amp;oldid=prev"/>
				<updated>2011-05-26T07:04:50Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 07:04, 26 May 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;L1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V)&amp;lt;/math&amp;gt;. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V)&amp;lt;/math&amp;gt; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;using a [[binary heap]], or &amp;lt;math&amp;gt;O(V(E + \log V))&amp;lt;/math&amp;gt; using a [[Fibonacci heap]]&lt;/ins&gt;. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Reweighting by vertex==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	<entry>
		<id>http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1319&amp;oldid=prev</id>
		<title>Brian: /* Reweighting by vertex */</title>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1319&amp;oldid=prev"/>
				<updated>2011-04-24T02:34:55Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Reweighting by vertex&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 02:34, 24 April 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;L8&quot; &gt;Line 8:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;What happens to a path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;? Suppose the path is given by &amp;lt;math&amp;gt;s = v_0, v_1, v_2, ..., v_n = t&amp;lt;/math&amp;gt;. Then the original weight of this path is &amp;lt;math&amp;gt;w(v_0,v_1) + w(v_1+v_2) + ... + w(v_{n-1},v_n)&amp;lt;/math&amp;gt;. After reweighting, the weight of this path becomes :&amp;lt;math&amp;gt;\begin{array}{ll}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;What happens to a path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;? Suppose the path is given by &amp;lt;math&amp;gt;s = v_0, v_1, v_2, ..., v_n = t&amp;lt;/math&amp;gt;. Then the original weight of this path is &amp;lt;math&amp;gt;w(v_0,v_1) + w(v_1+v_2) + ... + w(v_{n-1},v_n)&amp;lt;/math&amp;gt;. After reweighting, the weight of this path becomes :&amp;lt;math&amp;gt;\begin{array}{ll}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;amp; w(v_0,v_1) + h(v_1)-h(v_0) + w(v_1,v_2) + h(v_2) - h(v_1) + ... + w(v_{n-1},v_n) + h(v_n) - h(v_{n-1}) \\&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;amp; w(v_0,v_1) + h(v_1)-h(v_0) + w(v_1,v_2) + h(v_2) - h(v_1) + ... + w(v_{n-1},v_n) + h(v_n) - h(v_{n-1}) \\&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + (h(v_1)-h(v_0)) + (h(v_2)-h(v_1) + ... + (h(v_n)-h(v_{n-1}) \\&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + (h(v_1)-h(v_0)) + (h(v_2)-h(v_1&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;)&lt;/ins&gt;) + ... + (h(v_n)-h(v_{n-1}&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;)&lt;/ins&gt;) \\&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + h(v_n) - h(v_0) \\&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + h(v_n) - h(v_0) \\&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + h(t) - h(s)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + h(t) - h(s)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	<entry>
		<id>http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1050&amp;oldid=prev</id>
		<title>Brian: Created page with &quot;'''Johnson's algorithm''' is a technique for finding all-pairs shortest paths in a graph in which some edge weights may be negative (but there are no cycles of negative weigh...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wcipeg.com/wiki/index.php?title=Johnson%27s_algorithm&amp;diff=1050&amp;oldid=prev"/>
				<updated>2011-03-04T20:28:36Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;Johnson&amp;#039;s algorithm&amp;#039;&amp;#039;&amp;#039; is a technique for finding &lt;a href=&quot;/wiki/All-pairs_shortest_paths&quot; class=&quot;mw-redirect&quot; title=&quot;All-pairs shortest paths&quot;&gt;all-pairs shortest paths&lt;/a&gt; in a graph in which some edge weights may be negative (but there are no cycles of negative weigh...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''Johnson's algorithm''' is a technique for finding [[all-pairs shortest paths]] in a graph in which some edge weights may be negative (but there are no cycles of negative weight). It works by executing the [[Bellman–Ford algorithm]] once, using the data obtained to &amp;quot;reweight&amp;quot; the graph, eliminating negative weights, and then running [[Dijkstra's algorithm]] &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; times. Accordingly, its runtime is &amp;lt;math&amp;gt;O(VE+V(E+V)\log V)&amp;lt;/math&amp;gt;. Because of this, it is faster to use the [[Floyd–Warshall]] algorithm when the graph is dense, but Johnson's algorithm is faster when the graph is sparse.&lt;br /&gt;
&lt;br /&gt;
==Reweighting by vertex==&lt;br /&gt;
We want to change the weights of edges in the graph so that we can eliminate negative-weight edges, but we have to do so in such a way that the shortest paths do not change at all, otherwise the algorithm will simply not work. We shall do this by reweighting the graph in such a way that, given two vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;, the weight of a path ''after'' the reweighting is always equal to the weight of the path ''before'' the reweighting, plus some constant that depends only on &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; but not the path.&lt;br /&gt;
&lt;br /&gt;
A straightforward way of doing this is ''reweighting by vertex''. We shall initially assign each ''vertex'' &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; a ''height'' &amp;lt;math&amp;gt;h(v)&amp;lt;/math&amp;gt;. After we have done this, we will change the weight of any edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;w(u,v)&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;w(u,v)+h(v)-h(u)&amp;lt;/math&amp;gt;. (Intuitively, think of height literally, ''i.e.'', as an altitude, so that whenever we walk along an edge from &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is higher, it becomes &amp;quot;harder&amp;quot;, ''i.e.'', like a higher distance, and if it is lower, it is like a lower distance.)&lt;br /&gt;
&lt;br /&gt;
What happens to a path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;? Suppose the path is given by &amp;lt;math&amp;gt;s = v_0, v_1, v_2, ..., v_n = t&amp;lt;/math&amp;gt;. Then the original weight of this path is &amp;lt;math&amp;gt;w(v_0,v_1) + w(v_1+v_2) + ... + w(v_{n-1},v_n)&amp;lt;/math&amp;gt;. After reweighting, the weight of this path becomes :&amp;lt;math&amp;gt;\begin{array}{ll}&lt;br /&gt;
&amp;amp; w(v_0,v_1) + h(v_1)-h(v_0) + w(v_1,v_2) + h(v_2) - h(v_1) + ... + w(v_{n-1},v_n) + h(v_n) - h(v_{n-1}) \\&lt;br /&gt;
=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + (h(v_1)-h(v_0)) + (h(v_2)-h(v_1) + ... + (h(v_n)-h(v_{n-1}) \\&lt;br /&gt;
=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + h(v_n) - h(v_0) \\&lt;br /&gt;
=&amp;amp; w(v_0,v_1) + w(v_1,v_2) + ... + w(v_{n-1},v_n) + h(t) - h(s)&lt;br /&gt;
\end{array}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So ''every'' path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; has a new weight equal to its original weight plus the difference in heights between the source and destination, which means a shortest path before the reweighting is still a shortest path after the reweighting, as promised. (With a bit of imagination, this still makes sense intuitively. Imagine the initially flat terrain is subject to geological activity that causes it to become uneven. If the source and the destination are still at the same height, for example, it doesn't matter what happened to the heights ''along'' the shortest path --- the amount of uphill has to equal the amount of downhill, crudely speaking, since you end up at the same height at the end. It's just not immediately obvious because even though uphill is harder for us, downhill is not really easier.)&lt;br /&gt;
&lt;br /&gt;
==Eliminating negative-weight edges==&lt;br /&gt;
First, notice that reweighting by vertex cannot eliminate negative-weight cycles. This is because a cycle's weight will not change under reweighting, as a cycle can be considered a path from a vertex to itself (no height difference). However, it is always possible to make all edges non-negative provided that there are no negative-weight cycles.&lt;br /&gt;
&lt;br /&gt;
To do so, we shall make use of the following Lemma:&lt;br /&gt;
&lt;br /&gt;
''Lemma'': Given three nodes &amp;lt;math&amp;gt;s, u, v \in V&amp;lt;/math&amp;gt;, where a path exists from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; and an edge exists from &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, the weight &amp;lt;math&amp;gt;w(u,v)&amp;lt;/math&amp;gt; is at least &amp;lt;math&amp;gt;d(s,v) - d(s,u)&amp;lt;/math&amp;gt;. (Here, &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; represents the distance function.)&lt;br /&gt;
&lt;br /&gt;
''Proof'': If &amp;lt;math&amp;gt;w(u,v) &amp;lt; d(s,v) - d(s,u)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;d(s,u) + w(u,v) &amp;lt; d(s,v)&amp;lt;/math&amp;gt;. But this means we can take the shortest path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and append the edge &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; to obtain a path from &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; with weight less than &amp;lt;math&amp;gt;d(s,v)&amp;lt;/math&amp;gt;, a contradiction. (This is equivalent to saying that relaxation is still possible.) &amp;lt;math&amp;gt;_{\blacksquare}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now what happens if we fix a source &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and set the height of each vertex &amp;lt;math&amp;gt;v \in V&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;-d(s,v)&amp;lt;/math&amp;gt;? Then, the new weight of each edge &amp;lt;math&amp;gt;(u,v) \in E&amp;lt;/math&amp;gt; becomes &amp;lt;math&amp;gt;w(u,v) + h(v) - h(u) = w(u,v) - d(s,v) + d(s,u) \geq 0&amp;lt;/math&amp;gt; by the Lemma. So we have successfully eliminated all negative weights. All we have to do is find the single-source shortest paths first, which is done using the Bellman–Ford algorithm.&lt;br /&gt;
&lt;br /&gt;
Because the graph may not be connected, it may not be possible to fix a single source &amp;lt;math&amp;gt;s \in V&amp;lt;/math&amp;gt; that allows all weights to be calculated at once. To circumvent this problem and allow just one invocation of Bellman–Ford to succeed, we first introduce an extra vertex into the graph, connecting it via edges of weight 0 to all other vertices. (But this vertex must be removed before we proceed to the next step.)&lt;br /&gt;
&lt;br /&gt;
==Home stretch==&lt;br /&gt;
Having reweighted the graph appropriately, we can now run Dijkstra's algorithm once using each vertex as a source.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2001), ''Introduction to Algorithms'', MIT Press and McGraw-Hill, ISBN 978-0-262-03293-3 . Section 25.3, &amp;quot;Johnson's algorithm for sparse graphs&amp;quot;, pp. 636–640.&lt;br /&gt;
&lt;br /&gt;
[[Category:Algorithms]]&lt;br /&gt;
[[Category:Graph theory]]&lt;/div&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	</feed>