图——拓扑排序(Graph - Topological Sort)
简介(Introduction)
We know some problems in real life can be modelled as graph like task planning. Assume a directed edge from a to b means that task a must be done before b can be started. Assume those tasks are assigned to a single staff. Can you give a task order ?
In graph, we’re actually trying to linearise a DAG(directed cycle graph). That’s in the order sequence v1, v2, v2, .. , vk. For each edge(vi, vj) in E we have i < j.
示例(Example)
算法一(Algorithm1)
1. Perform DFS and note the order that are posed off the stack.
2. List the nodes in the reverse of that order.
算法二(Algorithm2)
Repeatedly select a random source in the
graph (that is, a node with no incoming edges),
list it, and remove it from the graph.
写在最后的话(PS)
Topological sort can help us decide whether a graph has a cycle. if(vj, vi) and i < j.
Welcome questions always and forever.
本文介绍了如何通过两种算法实现图的拓扑排序:一种是基于深度优先搜索的算法,另一种则是通过反复选择没有入边的节点进行排序。拓扑排序有助于判断图中是否存在环,并能为任务规划等实际问题提供解决方案。
2316

被折叠的 条评论
为什么被折叠?



