algorithm@ find the shortest path in a graph using BFS
2016-03-16 03:34
741 查看
[b]Finding Shortest Paths By BFS[/b]
The BFS code we have seen
find outs if there exist a path from a vertex s to a vertex v
prints the vertices of a graph (connected/strongly connected).
What if we want to find
the shortest path from s to a vertex v (or to every other vertex)?
the length of the shortest path from s to a vertex v?
In addition to array flag[ ], use an array named prev[ ], one element per vertex.
prev[w] = v means that vertex w was visited right after v
The BFS code we have seen
find outs if there exist a path from a vertex s to a vertex v
prints the vertices of a graph (connected/strongly connected).
What if we want to find
the shortest path from s to a vertex v (or to every other vertex)?
the length of the shortest path from s to a vertex v?
In addition to array flag[ ], use an array named prev[ ], one element per vertex.
prev[w] = v means that vertex w was visited right after v
相关文章推荐
- 蓝桥杯 ALGO-122(记忆化搜索)
- SENGO森果网招商
- HOTPOWER.【专注游戏界面外包】/接游戏界面外包/logo外包/icon
- Django入门(九) ajax异步请求
- google zxing生成二维码
- 【每周一文】Googles News Personalization:Scalable Online Collaborative Filtering(2007)
- go源码阅读笔记(math.1)
- Django: 配置和静态文件
- 一张图解AlphaGo原理及弱点
- 一张图解AlphaGo原理及弱点
- 一张图解AlphaGo原理及弱点
- lightoj 1259 - Goldbach`s Conjecture 【素数筛】
- Chat Server's Outgoing Traffic(求助文)
- 搭建Go开发及调试环境(LiteIDE + GoClipse) -- Windows篇
- 蓝桥杯 ALGO-8(线段树)
- Agglomerative Hierarchical Algorithms(凝聚式层次聚类)
- liteIDE的报错: go: cannot find GOROOT directory: c:\go
- Go语言核心之美 1.5-作用域
- Django 开发Tutorial part_2
- POJ-1003-hangover