正在加载图片...
Topological Sort It is clear that a topological ordering is not possible if the graph has a cycle,since for two vertices vand w on the cycle,vprecedes wand wprecedes v. The ordering is not necessarily unique;any legal ordering will do. A simple algorithm to find a topological ordering is first to find any vertex with no incoming edges.We can then print this vertex,and remove it,along with this edge,from the graph.Then we apply this same strategy to the rest of the graph. Thus,we compute the indegrees of all vertices in the graph,and look for a vertex with indegree 0 that has not already been assigned a topological number.Topological Sort ◼ It is clear that a topological ordering is not possible if the graph has a cycle, since for two vertices v and w on the cycle, v precedes w and w precedes v. ◼ The ordering is not necessarily unique; any legal ordering will do. ◼ A simple algorithm to find a topological ordering is first to find any vertex with no incoming edges. We can then print this vertex, and remove it, along with this edge, from the graph. Then we apply this same strategy to the rest of the graph. ◼ Thus, we compute the indegrees of all vertices in the graph, and look for a vertex with indegree 0 that has not already been assigned a topological number
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有