BFS时间复杂度问题
来源:互联网 发布:网络招聘平台对比 编辑:程序博客网 时间:2024/05/21 08:29
BFS(s):
Set Discovered[s] = true and Discovered[v] = false for all other vInitialize L[0] to consist of the single element sSet the layer counter i = 0Set the current BFS tree T =∅While L[i] is not empty Initialize an empty list L[i + 1] For each node u ∈ L[i] Consider each edge (u, v) incident to u If Discovered[v] = false then Set Discovered[v] = true Add edge (u, v) to the tree T Add v to the list L[i + 1] Endif Endfor Increment the layer counter i by oneEndwhile
解: 最多有n个list需要set up,所以这个是O(n) time。每进一次while,for走的都是与u相连的edge的数量 + set下一个list, 算下来走完算法是O(m+n)。
0 0
- BFS时间复杂度问题
- HashMap时间复杂度问题
- bfs时间复杂度及优化方向
- 类快排的时间复杂度问题
- 有关时间复杂度的问题
- 汉诺塔问题以及时间复杂度
- 时间复杂度的计算问题
- 图dfs和bfs时的时间复杂度
- 【c++】关于时间复杂度和空间复杂度的相关问题
- 估算递归问题的时间复杂度方法
- 关于SelfNumbers问题时间复杂度问题解决方案
- 求递归式的时间复杂度问题
- 递归算法时间复杂度的估计问题
- 非多项式时间复杂度及NP问题
- 选择问题(线性时间复杂度)
- 冒泡算法的时间复杂度问题
- 时间复杂度和最大子序列问题
- 算法的时间和空间复杂度问题
- JAVA数据类型转换
- 初探java内存机制
- 再谈Java数据类型
- LINUX挂载光驱
- 游戏并购再创高峰,第三季度高达122亿美金,是去年总额的两倍
- BFS时间复杂度问题
- [Leetcode] Search for a Range
- Android之Applicaton使用总结
- lm358 压腔震荡器 分析
- 积分与微分电路 (转)
- myeclipse6.5运行后, 经常自动退出
- Leetcode: Maximum Product Subarray
- 开始写博客 CSDN我的博客字体规范
- [Leetcode] Multiply Strings