the shortest path algorithm
Dijkstra算法
又称迪杰斯特拉算法,是一个经典的最短路径算法,主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止,使用了广度优先搜索解决赋权有向图的单源最短路径问题,算法最终得到一个最短路径树。时间复杂度为O(N^2)
执行动画:
实例:
抽象步骤:
1.将起点A放入集合中,A点的权值为0,因为A->A=0。
2.与起点A相连的所有点的权值设置为A->点的距离,连接不到的设置为无穷。并且找出其中最小权值的B放入集合中(此时A->B必定为最小距离)。
3.与B点相连的所有点的权值设置为B->点的距离,并且找出其中最小权值的C点放入集合中(此时C的权值必定为其最小距离)。
4.重复步骤3,直至所有点加入集合中。便能得到所有点与A点的最短距离。
Floyd算法
全称Floyd-Warshall算法,又称佛洛依德算法,是解决任意两点间的最短路径的一种算法,但是时间复杂度比迪杰斯特拉要高,时间复杂度为O(N^3)吗,空间复杂度为O(N^2)。
简单案例:
步骤:
1.将图转化成矩阵:
2.选择V0点作为第一个中间点:
3.进行V0中间点是否能缩短另外两点间距离的判断:简而言之就是非对角线处(红箭头处)进行加法判断,<则替换。
4.对后续点进行步骤2-3相应的操作。
范例:
INF表示无穷大。
from:
http://blog.csdn.net/jerry81333/article/details/54772709
the shortest path algorithm的更多相关文章
- 最短路径Shortest Path algorithm
最短路径问题: 如果从图中某一顶点(称为端点)到达另一顶点(称为终点)的路径可能不止一条,如何找到一条路径使得沿此路径上各边上的权值总和达到最小. (1)Dijkstra 算法 (2) Floyd 算 ...
- A Fast Priority Queue Implementation of the Dijkstra Shortest Path Algorithm
http://www.codeproject.com/Articles/24816/A-Fast-Priority-Queue-Implementation-of-the-Dijkst http:// ...
- Method for finding shortest path to destination in traffic network using Dijkstra algorithm or Floyd-warshall algorithm
A method is presented for finding a shortest path from a starting place to a destination place in a ...
- 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. ...
- zoj 2760 How Many Shortest Path 最大流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...
- The Shortest Path in Nya Graph
Problem Description This is a very easy problem, your task is just calculate el camino mas corto en ...
- Shortest Path(思维,dfs)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- Shortest Path
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- (中等) HDU 4725 The Shortest Path in Nya Graph,Dijkstra+加点。
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...
随机推荐
- Confluence 6 升级以后
7. 拷贝你的数据库驱动 如果你现在使用的是 Oracle 或者 MySQL 数据库的话,你讲要重新拷贝 jdbc 驱动的 jar 文件到你已经存在的 Confluence 安装目录中 conflue ...
- android studio 编辑markdown文件
作为开发人员,对markdown应该比较熟悉,我们在Android开始中,可以使用studio引入Markdown Navigator插件,进行编辑. 搜索 Markdown Navigator 安装 ...
- python - 闭包,迭代器
一.第一类对象 1.函数名的运用 函数名是一个变量,但它是一个特殊的变量,与括号配合可以执行函数的变量 1.函数名的内存地址 def func1(): print('你是谁,你来自哪里 ...
- 分享张鑫旭大神的,纯css打字小技巧,我顺便收藏一下
CSS代码: .typing { width: 15em; white-space: nowrap; border-right: 2px solid transparent; animation: t ...
- Cross-Validation & Nested Cross-Validation
分享stackexchange的一篇问答:https://stats.stackexchange.com/questions/11602/training-with-the-full-dataset- ...
- linux常用命令 cut字符截取命令
cut 字符截取 cut [选项] 文件名 选项 -f 列号: 提取第几列 -d 分割符:按照指定的分隔符分割列 默认使用制表符("tab")进行分割 ssgao:Download ...
- mysql存储过程和执行计划案例
开启event_scheduler指令: SET GLOBAL event_scheduler = ON;SET @@global.event_scheduler = ON;SET GLOBAL ev ...
- Tomcat启动后,访问页面报404错误解决方法
Tomcat正常启动后,出现如下情况 提供一个参考解决方法: 1.双击servers 2.把Server Locations设置为User Tomcat installation 保存后再次访问页面就 ...
- presto 判断数据量是否大于一个比较小的值的优化
问题来源于以下场景: 我们需要对一张数据表做导出文件操作,需要判断如果数据量不多的时候,直接导出提供下载,如果数据量超过一定数值,则异步处理导出和下载. 这里就引入一个问题,如果我们直接count一张 ...
- windows版influxDB安装与配置
一.下载链接https://portal.influxdata.com/downloads,选windows版 二.解压到安装盘,目录如下 三.修改conf文件,代码如下,直接复制粘贴(1.4.2版本 ...