python -- 广度优先搜索
来源:互联网 发布:淘宝商品不合格违规了 编辑:程序博客网 时间:2024/06/05 15:07
#! /usr/bin/env python3# -*- coding: utf-8 -*-from collections import dequegraph = {}graph['A'] = ['B', 'F']graph['B'] = ['C']graph['C'] = ['D']graph['F'] = ['E', 'G']graph['E'] = ['C']#graph['E'] = []graph['G'] = ['C']graph['D'] = []def broadsearch(start, target):search_queue = deque()search_queue += graph[start]got = Falsesearched = []while search_queue:node = search_queue.popleft()if node not in searched:print(node)if node == target:#print("Found it!")got = Trueelse:search_queue += graph[node]searched.append(node)print("Process is" + str(searched))return gotif __name__ == "__main__":getprocess = broadsearch('A', 'D')if getprocess:print("Found it")else:print("Not Found it")
ps:
广度优先搜索用于在非加权图中查找最短路径。
Dijkstra狄克斯特拉算法用于在加权图中查找最短路径。仅当权重为正时狄克斯特拉算法才管用。
如果图中包含负权边,请使用贝尔曼-福德算法。
阅读全文
0 0
- python -- 广度优先搜索
- 图的广度优先搜索--python实现
- python自然语言处理-广度优先搜索
- 广度优先搜索算法
- 双向广度优先搜索
- 广度优先搜索法
- pku2251(广度优先搜索)
- POJ1184Clerver_Writer:广度优先搜索
- Java广度优先搜索
- [AI]广度优先搜索
- 广度优先搜索-BFS
- 广度优先搜索算法
- 广度优先搜索算法
- BFS广度优先搜索
- 广度优先搜索 BFS
- 广度优先搜索
- [ 算法 ]广度优先搜索!
- 广度优先搜索
- 第四章.-10 Python从入门到实践
- scada 遥控选择执行取消
- centos上目标检测(二)
- Unity3d 与串口的通信程序的开发,软件硬件结合
- initUndistortRectifyMap
- python -- 广度优先搜索
- 关于EasyUI Datagrid 数据网格渲染数据过慢
- 深入理解Spring--动手实现一个简单的SpringIOC容器-非注解版
- Spring学习总结(24)——Spring配置文件加载路径总结
- 函数表达式(2)
- ros tab补全问题
- Delcam PowerInspect 2014\
- java默认VM设置--myEclipse
- SpringBoot 调度任务