BFS&Python
来源:互联网 发布:什么软件有淘宝优惠卷 编辑:程序博客网 时间:2024/06/05 08:20
# 邻接矩阵graph = [ [0,1,1,0,0,0,0,0], [1,0,1,1,1,0,0,0], [1,1,0,0,1,0,1,1], [0,1,0,0,0,0,0,0], [0,1,1,0,0,1,0,0], [0,0,0,0,1,0,0,0], [0,0,1,0,0,0,0,0], [0,0,1,0,0,0,0,0]]# 记录定点是否被到达discovered = [False]*len(graph)# 起点记录为 Truediscovered[0] = True# L[0] = [0] L[0]只包含一个初始节点L = []L.append([0])# 记录层数i = 0edges = [] # 记录搜索树上的边while len(L[i]) != 0: temp = [] for node in L[i]: # 对这一层中的每一个节点进行遍 for j in range(len(graph)): # 查找与其相邻的边 if graph[i][j]: if discovered[j] == False: # 另一个定点没有被访问过就加入i+1层 discovered[j] = True temp.append(j) edges.append((i,j))# 往搜索树中插入一条边 i += 1 L.append(temp)for item in L: if len(item): print(item)
阅读全文
0 0
- BFS&Python
- python 处理八数码 双向BFS 拼图游戏
- checkio -- Open Labyrinth python BFS的使用
- BFS求解N数码(python)
- BFS
- bfs
- BFS
- BFS
- bfs
- BFS
- bfs
- BFS
- BFS
- bfs
- BFS
- BFS
- BFS
- BFS
- linux挂载详解
- PyQt5笔记(06) -- 菜单
- linux lua编译
- Pyhon基础:Monkey Patch(猴子补丁)
- 事务及事务的特性
- BFS&Python
- KMP算法实现
- Java标识符的命名规则
- [聊聊架构] 日请求量过亿,谈陌陌的 Feed 服务优化之路
- Strings
- Scala和Java方法的相互调用
- 数组和指针一道非常值得深思的笔试题
- Multiple Object Tracking with High Performance Detection and Appearance Feature
- UGUI综合