Proof for Floyd-Warshall's Shortest Path Derivation Algorithm Also Demonstrates the Hierarchical Path Construction Process
(THIS BLOG WAS ORIGINALLY WRTITTEN IN CHINESE WITH LINK: http://www.cnblogs.com/waytofall/p/3732920.html)
Foreword: Floyd-Warshall is a classical dynamical programming algorithm for deriving shortest paths between each pair of nodes on a graph. It has n iterations (n for the number of nodes). During each iteration k, the shortest paths for each pair of nodes with intermediate nodes numbered no more than k are derived. Since inductively, we can assume that before iteration k, the shortest paths for each pair of nodes with intermediate nodes numbered no more than k-1 are derived, the way to derive the paths with intermediate nodes numbered no more than k can be derived as:

In order to derive all the intermediate nodes on a shortest path, the algorithm maintains a predecessor matrix Π, with its element πij denoting the node before j in the shortest path from i to j. The matrix is defined as follows:


For more detailed specification, please refer to Introduction to Algorithms.
My problem: for two nodes i, j of graph, there is a maximal k, such that during the kth iteration, the shortest paths dynamically programmed by the algorithm was combined by shortest paths i ~ k, k ~ j, whose intermediate nodes are numbered less than k. And for the shortest paths i ~ k, k ~ j, we can also have such a iteration. Therefore, the path can be visualised as follows:

In the tree displayed above, each parent is separated by the "middle node" k, which is the maximal number of iteration that combines two paths. The shortest paths derived from the predecessor matrix are easily proved correct, but the problem is, whether the paths derived by such methods are identical to the paths displayed by the figure above? In another word, whether the paths derived demonstrate the hierarchical path construction process of Floyd-Warshall? The answer is yes. And I'm gonna prove it.
Lemma 1: If, during the kth iteration, the shortest path from i to j was derived by combining paths i ~ k, k ~ j, and we have m = πij(k) and m ≠ k; then the shortest path constructed by the algorithm from i to m also are derived from combining i ~ k, k ~ m.
Proof: Since πkj(k-1) = πij(k)= m, that is, in the path from k to j with intermediate nodes numbered no more than k, the predecessor of j is m, so we have:
dkj(k-1) = dkm(k-1) + wmj
wmj is the weight for edge(m, j).
Since there is an edge from m to j, from the Triangle Inequality, we have:
dij(k-1) ≤ dim(k-1) + wmj (1)
which is:
dim(k-1) ≥ dij(k-1) - wmj (2)
From the condition of the lemma, we have:
dij(k-1) > dik(k-1) + dkj(k-1) (3)
Subtract wmj from both sides, we have:
dij(k-1) - wmj > dik(k-1) + dkj(k-1) - wmj = dik(k-1) + dkm(k-1) (4)
Which can be transformed to:
dij(k-1) - wmj > dik(k-1) + dkm(k-1) (5)
Combining (2) and (5), we have:
dim(k-1) > dik(k-1) + dkm(k-1) (6)
Done.
Then we are going to prove our conclusion.
Proof: We use mathematical induction. Before the first iteration, the paths derived from the Π(0) matrix certainly meet the property.
Then, supposing that path derived from Π(k-1) meet the property, then in the kth iteration:
(1). If the shortest path from i to j does not contain node k, we have dij(k) = dij(k-1),πij(k) = πij(k-1) = m. Applying the shortest path construction function, we can have a nodes sequence:
πij(k) = m
πim(k) = n
...
πio(k) = p
πip(k) = i
For any πix(k) (x belongs to {m,n,...,p,i}), πix(k) =πix(k-1). So we have:
πij(k) = πij(k-1) = m
πim(k) = πim(k-1) = n
...
πio(k) = πio(k-1) = p
πip(k) = πip(k-1) = i
That is, the shortest paths derived from Π(k) is identical to the shortest paths derived from Π(k-1). Since Π(k) has the propery, the path also has the property.
(2). If the shortest path from i to j contains node k, we have:
dij(k) = dik(k-1) + dkj(k-1),πij(k) = πkj(k-1)= m
and:
πij(k) = πkj(k-1) = m
πim(k) = πkm(k-1) = n
...
πio(k) = πko(k-1) = p
πip(k) = πkp(k-1) = k
That is, we enumerate the predecessor of j until we get to k. Now, all the intermediate nodes of the path from i to k are identical to the path derived from Π(k-1), so the subpath meet the property. The same for path from k to j, so the shortest paths from i to j derived from Π(k) meet the property.
Done.
Proof for Floyd-Warshall's Shortest Path Derivation Algorithm Also Demonstrates the Hierarchical Path Construction Process的更多相关文章
- 图论之最短路径(1)——Floyd Warshall & Dijkstra算法
开始图论学习的第二部分:最短路径. 由于知识储备还不充足,暂时不使用邻接表的方法来计算. 最短路径主要分为两部分:多源最短路径和单源最短路径问题 多源最短路径: 介绍最简单的Floyd Warshal ...
- SPFA(Shortest Path Faster Algorithm)
特别说明 本文转载自三金(frinemore)的博客: 点这 前言 1.关于SPFA,它没死. 2.接下来的所有代码,都是自己手写的(未检查正确性,补充的代码有检查过,是对的),有错误请帮忙指出. S ...
- 安装vmware-tools遇the path "" is not valid path to the gcc binary和the path "" is not a valid path to the 3.10.0-327.e17.x86_64 kernel headers问题解决
#./vmware-install.pl踩点: 1.the path "" is not valid path to the gcc binary 2.the path " ...
- 安装vm tools时出现如下问题 The path "/usr/bin/gcc" is not valid path to the
sudo suapt-get updateapt-get dist-upgradeapt-get install open-vm-tools-desktop fusereboot https://bl ...
- os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息
import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...
- zk 09之:Curator之二:Path Cache监控zookeeper的node和path的状态
在实际应用开发中,当某个ZNode发生变化后我们需要得到通知并做一些后续处理,Curator Recipes提供了Path Cache 来帮助我们轻松实现watch ZNode. Path Cache ...
- os.path.dirname(__file__)使用、Python os.path.abspath(__file__)使用
python中的os.path.dirname(__file__)的使用 - CSDN博客https://blog.csdn.net/u011760056/article/details/469698 ...
- Floyd —Warshall(最短路及其他用法详解)
一.多元最短路求法 多元都求出来了,单源的肯定也能求. 思想是动态规划的思想:从任意节点A到任意节点B的最短路径不外乎2种可能,1是直接从A到B,2是从A经过若干个节点X到B.所以,我们假设Dis(A ...
- 图论学习笔记·$Floyd$ $Warshall$
对于图论--虽然本蒟蒻也才入门--于是有了这篇学习笔记\(qwq\) 一般我们对于最短路的处理,本蒟蒻之前都是通过构建二维数组的方式然后对每两个点进行1次深度或者广度优先搜索,即一共进行\(n\)^2 ...
随机推荐
- Horizon的本地化
1. 准备工作 apt-get install gettext horizon源码下载路径 /workspace/horizon/ 2. 生成mo文件 django-admin.py makeme ...
- js 值和引用
js对值和引用的赋值/传递在语法上没有区别,完全根据值得类型决定 简单值(即标量基本类型值),总是通过值复制的方式来赋值/传递,包括null,undefined,字符串,数字,布尔值和ES6中的sym ...
- 每天一个linux命令:【转载】cp命令
cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...
- BZOJ2653 middle 【主席树】【二分】*
BZOJ2653 middle Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整.给你一个长度为n的序列s.回答Q个这样 ...
- BZOJ1208 HNOI2004 宠物收养所 【非旋转Treap】
BZOJ1208 HNOI2004 宠物收养所 Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的 ...
- 不再为命名而苦恼!使用 MSTestEnhancer 单元测试扩展,写契约就够了
有没有觉得命名太难?有没有觉得单元测试的命名更难?没错,你不是一个人!看看这个你就知道了:程序员最头疼的事:命名 或它的英文原文 Don’t go into programming if you do ...
- ResultSet.TYPE_SCROLL_SENSITIVE到底发生了什么?
转自:https://blog.csdn.net/axman/article/details/3984103 这个问题我在几年前说过,但今天再次从CSDN上看到有人问这个问题,可以看出,真正懂这个问题 ...
- 《selenium2 python 自动化测试实战》(9)——切换窗口
有时候我们点击按钮后页面会跳转到新的窗口,我们需要到新的窗口中去进行接下来的操作,这时候就需要切换窗口的操作,我们根据句柄(handle)来操作窗口之间的切换,看代码: # coding: utf-8 ...
- VScode插件
Visual Studio Code (简称 VS Code / VSC) 是一款免费开源的现代化轻量级代码编辑器,支持几乎所有主流的开发语言的语法高亮.智能代码补全.自定义热键.括号匹配.代码片段. ...
- [语法]C语言中二维数组做输入参数
C语言中二维数组做输入参数时, 可以同时指定各维长度, 可以只指定第二维的长度, 不可以只指定第一维的长度, 不可以各维长度都不指定. 一句话总结:要指定至少指定第二维,都不指定是不行的. 具体栗子如 ...