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的更多相关文章

  1. 最短路径Shortest Path algorithm

    最短路径问题: 如果从图中某一顶点(称为端点)到达另一顶点(称为终点)的路径可能不止一条,如何找到一条路径使得沿此路径上各边上的权值总和达到最小. (1)Dijkstra 算法 (2) Floyd 算 ...

  2. 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:// ...

  3. 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 ...

  4. 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. ...

  5. zoj 2760 How Many Shortest Path 最大流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...

  6. The Shortest Path in Nya Graph

    Problem Description This is a very easy problem, your task is just calculate el camino mas corto en ...

  7. Shortest Path(思维,dfs)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  8. Shortest Path

    Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. (中等) 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 ...

随机推荐

  1. Petrozavodsk Winter Camp, Day 8, 2014, Fine Brochures

    1的个数-块的个数+多减的个数+flag 多减的只会在一个循环末尾出现 #include <bits/stdc++.h> using namespace std; #define rep( ...

  2. Js 语言中 变量提升问题

    变量提升: 提升变量的声明. 函数声明式: 像这种形式: function foo() {}: 会发生变量提升. 函数表达式: var fn=function fn(){}: 不会发生变量提升.var ...

  3. linux top指令信息表示

    top指令: PID ====  进程号 USER ==== 进程所有者 PR ====  进程优先级 NI ====  进程优先级别数值 VIRT ==== 进程占用的虚拟内存 RES ====   ...

  4. C#异步(下)

    上篇主要分析了async\await之前的一些异步模式,今天说异步的主要是指C#5的async\await异步.在此为了方便的表述,我们称async\await之前的异步为“旧异步”,async\aw ...

  5. Assignments 1

    跑了一下之前写的UiPath Assignments脚本,没什么问题,发上来供大家参考. 先看结果: github:https://github.com/WendyZheng1022/RPA 有时间我 ...

  6. Vue的学习

    1.Vue是什么 参考Vue官网,一套用于构建用户界面的渐进式框架. 2.什么是渐进式框架 引用大神的话:“它给你提供足够的optional,但并不主张很多required,也不多做职责之外的事!这就 ...

  7. java根据#号截取字符串,使用Pattern的方法

    public class Regex1 { public static void main(String[] args) { String s = "神秘的海洋出现了一只#话题#海怪阿拉斯加 ...

  8. 软件151 王楚博 aodp

    一.AOP是OOP的延续,是(Aspect Oriented Programming)的缩写,意思是面向切面编程. AOP(Aspect Orient Programming),作为面向对象编程的一种 ...

  9. How to find out which version of tensorflow is installed in my pc? - 如何找出我的电脑中安装了哪个版本的 tensorflow?

    I'm using tensorflow and have got some weired issues. I'm told it might be related to the version of ...

  10. tensorflow 经典教程及案例

    导语:本文是TensorFlow实现流行机器学习算法的教程汇集,目标是让读者可以轻松通过清晰简明的案例深入了解 TensorFlow.这些案例适合那些想要实现一些 TensorFlow 案例的初学者. ...