How To Get Min-Cost Between two points in graph (Dijkstra’s algorithm)
来源:互联网 发布:毕业生贷款分期软件 编辑:程序博客网 时间:2024/05/23 13:39
How To Get Min-Cost Between twopoints in graph
(Dijkstra’s algorithm)
Now See This Graph :
which is just like asubway map .
Now Question is :
how to calculate fromA to (B,C,D,E,F,G,H,I,J) min cost ?
Now Let's go through Dijkstra's algorithm.
I will start follow these steps :
Step 1:
Take point from (A,B,C,D,E,F,G,H,I,J) .
Step 2:
find out the points it can reach ,save as reached-points
Step 3:
update the reached-points distance by the new dist if it issmaller than the old value
ok , now take A, and we can see ,A can reach B,C,D
Now I take B. B Can Reach D,E. SoI need to update the value for D,E
As 4+3 < 8 . sothe value for D updated to 7.
Next ,Take C. C canreach D,F ,So I Need to update D,F values
Next ,Take D , D CanReach B,C,E,F,G , I Need to update them relatively .
But Can See ,D'svalue is 6 ,gather than B(4) and C(5) ,so no need update for B,C.
Next, Take E. whichCan Reach B,D,G,H
E(15)>B(4) ,E(15) > D(6), no updating.
E(15) + 6 >G(16),So no updating for G(16).
Next ,F .Can reach C,D,G,I
For C,D .
F(10) > D(6) ,F(10) > C(5) , so no updating .
Ok ,Next G. Whichcan reach D,E,F,H,I,J
G(15)>=E(15),G(15)>D(6),G(15) > F(10) .So No need update .now let's see how about H,I,J
G(15) + 3 < H(25)
G(15) + 5 <I(21)
J(30) is new added
so update them.
Next ,Take H. whichcan reach E,G,J
H(18) >E(15)=G(15) .No updating .
H(18) + 14 > J(30), also no updating .
Next ,Take I. CanReach F,G,J
I(20) >F(10),I(20)>G(15) , no updating
Let's see J
I(20) + 8 < J(30)
so update J(30)-> J(28)
Last ,Add J ,CanReach G,H,I
but J(28) >G(15),
J(28) > H(18),
J(28) > I(20)
so no updating .
- How To Get Min-Cost Between two points in graph (Dijkstra’s algorithm)
- lintcode:Route Between Two Nodes in Graph
- DFS-----Route Between Two Nodes in Graph
- #176 Route Between Two Nodes in Graph
- Route Between Two Nodes in Graph
- Route Between Two Nodes in Graph
- How to capture the one-to-one dependency between two attributes in one relation?
- Finding Path/Route Between two points on MapKit in iPhone
- Use python to implement Dijkstra's algorithm
- How To Set Up A Serial Port Between Two Virtual Machines In VirtualBox
- Lintcode176 Route Between Two Nodes in Graph solution 题解
- Karger's algorithm to solve global min-cut
- How to get the 2D coordinate of the max or min value in matrix in matlab
- Dijkstra算法(Dijkstra's algorithm)
- How to remove all characters between two brackets?
- How to move between two or more forms?
- How to move an OIM database between two OIM instances
- How-to: transfer hbase data between two hadoop cluster
- Android应用开发学习笔记之网格视图
- 游戏的登陆和离线流程思考
- hdoj1342
- Template Method模板方法模式
- 黑马程序员之java中一些小知识点(不断更新中)
- How To Get Min-Cost Between two points in graph (Dijkstra’s algorithm)
- 西部数码网站管理助手serv-u默认密码
- 【SQL】MySQL内置函数中的字符串函数和日期时间函数
- Hibernate关联关系之多对一
- 哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用
- 堆和栈的区别
- Overlay加载2d图片
- live555在arm linux下的交叉编译,并下载的Arm板播放H264文件
- uva 10161 - Ant on a Chessboard