图论总结

amber大牛的图论总结 1. 图论 Graph Theory 1.1. 定义与术语 Definition and Glossary 1.1.1. 图与网络 Graph and Network 1.1.2. 图的术语 Glossary of Graph 1.1.3. 路径与回路 Path and Cycle 1.1.4. 连通性 Connectivity 1.1.5. 图论中特殊的集合 Sets in graph 1.1.6. 匹配 Matching 1.1.7. 树 Tree 1.1.8. 组合优化 Combinatorial optimization 1.2. 图的表示 Expressions of graph 1.2.1. 邻接矩阵 Adjacency matrix 1.2.2. 关联矩阵 Incidence matrix 1.2.3. 邻接表 Adjacency list 1.2.4. 弧表 Arc list 1.2.5. 星形表示 Star 1.3. 图的遍历 Traveling in graph 1.3.1. 深度优先搜索 Depth first search (DFS) 1.3.1.1. 概念 1.3.1.2. 求无向连通图中的桥 Finding bridges in undirected graph 1.3.2. 广度优先搜索 Breadth first search (BFS) 1.4. 拓扑排序 Topological sort 1.5. 路径与回路 Paths and circuits 1.5.1. 欧拉路径或回路 Eulerian path 1.5.1.1. 无向图 1.5.1.2. 有向图 1.5.1.3. 混合图 1.5.1.4. 无权图 Unweighted 1.5.1.5. 有权图 Weighed — 中国邮路问题The Chinese post problem 1.5.2. Hamiltonian Cycle 哈氏路径与回路 1.5.2.1. 无权图 Unweighted 1.5.2.2. 有权图 Weighed — 旅行商问题The travelling salesman problem 1.6. 网络优化 Network optimization 1.6.1. 最小生成树 Minimum spanning trees 1.6.1.1. 基本算法 Basic algorithms 1.6.1.1.1. Prim 1.6.1.1.2. Kruskal 1.6.1.1.3. Sollin(Boruvka) 1.6.1.2. 扩展模型 Extended models 1.6.1.2.1. 度限制生成树 Minimum degree-bounded spanning trees 1.6.1.2.2. k小生成树 The k minimum spanning tree problem(k-MST) 1.6.2. 最短路Shortest paths 1.6.2.1. 单源最短路 Single-source shortest paths 1.6.2.1.1. 基本算法 Basic algorithms 1.6.2.1.1.1. Dijkstra 1.6.2.1.1.2. Bellman-Ford 1.6.2.1.1.2.1. Shortest path faster algorithm(SPFA) 1.6.2.1.2. 应用Applications 1.6.2.1.2.1. 差分约束系统 System of difference constraints 1.6.2.1.2.2. 有向无环图上的最短路 Shortest paths in DAG 1.6.2.2. 所有顶点对间最短路 All-pairs shortest paths 1.6.2.2.1. 基本算法 Basic algorithms 1.6.2.2.1.1. Floyd-Warshall 1.6.2.2.1.2. Johnson 1.6.3. 网络流 Flow network 1.6.3.1. 最大流 Maximum flow 1.6.3.1.1. 基本算法 Basic algorithms 1.6.3.1.1.1. Ford-Fulkerson method 1.6.3.1.1.1.1. Edmonds-Karp algorithm 1.6.3.1.1.1.1.1. Minimum length path 1.6.3.1.1.1.1.2. Maximum capability path 1.6.3.1.1.2. 预流推进算法 Preflow push method 1.6.3.1.1.2.1. Push-relabel 1.6.3.1.1
### 图论算法总结与例题 图论是一门研究图形结构及其性质的学科,在计算机科学中有广泛的应用。以下是几种常见的图论算法以及它们的相关例题。 #### 1. **广度优先搜索 (BFS)** 和 **深度优先搜索 (DFS)** 这两种基本的遍历方法可以用来解决许多基础问题,比如连通分量检测、路径寻找等。 - BFS通常适用于找到两点间的最短路径(无权图),其核心思想是以层次的方式扩展节点[^2]。 - DFS则常用于探索所有可能的状态或者回溯解决问题。 #### 2. **并查集** 并查集是一种处理动态集合的数据结构,主要用于快速判断两个元素是否属于同一个集合,并支持高效的合并操作。 - 并查集的主要功能包括查询和合并两部分。 #### 3. **最小生成树 (MST)** 最小生成树是指在一个加权连通图中找出一棵总权重最小的生成树。 - Prim算法通过不断选择离当前已构建的部分最近的顶点来逐步扩大这棵树[^1]。 - Kruscal算法则是按照边的权重从小到大依次考虑每条边,只要该边不会形成环就将其加入结果集中。 #### 4. **拓扑排序** 对于有向无环图(DAG),可以通过拓扑排序得到一个线性的顺序使得所有的前驱关系都满足。 - 方法通常是先统计入度再利用队列实现零入度节点移除的过程直到完成整个序列排列。 #### 5. **最短路径算法** 这些算法旨在计算从某个起点到达其他各点所需的最少成本。 - Dijkstra算法适合于非负权值的情况,它采用贪心策略每次挑选距离源点最近尚未访问过的节点作为新的候选者继续扩散影响范围[^3]。 - Bellman-Ford允许存在负权但需额外注意可能出现的负圈情况;SPFA是对前者的一种改进形式特别针对稀疏图表现更优[^4]。 - Floyd-Warshall能够一次性得出任意两点间最佳路线长度非常适合小型密集网络分析需求。 #### 实际应用举例 假设我们要设计一款游戏地图编辑器需要自动规划NPC巡逻线路,则可选用A*启发式寻径技术结合实际地形数据综合考量效率与合理性给出解决方案。 ```python import heapq def dijkstra(graph, start): distances = {node: float('infinity') for node in graph} distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if current_distance > distances[current_node]: continue for neighbor, weight in graph[current_node].items(): distance = current_distance + weight if distance < distances[neighbor]: distances[neighbor] = distance heapq.heappush(priority_queue, (distance, neighbor)) return distances ``` 以上代码片段展示了如何使用Python实现Dijkstra算法以求解给定图上某一点至其余各点之间的最短路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值