Some facts about topological sort
Definition: a topological sort of a DAG G is a sort such that for all edge (i,j) in G, i precedes j.
Then we have following corollaries:
- A sort is a topological sort of a DAG G iff for all i, j such that there is a path from i to j, i precedes j in the sort.
- A sort is a topological sort of a DAG G iff for all i, j, if i precedes j, then there is no path from j to i.
A Lemma:
- If in a DAG G, for i, j of G, there is no path from i to j and from j to i, then there must be a topological sort of G with i preceding j.
Proof:
Suppose there is a toplogical sort with j preceding i, then with the following procedure:
For every k between j and i, with the one nearest to j processed first:
If there is a path from k to i, then move k right before j
Move i right before j
We can derive a topological order with i preceding j without breaking the validity of the order. The reason is that, since k is between j and i, then there is no path from k to j and no path from i to k. If there is a path from k to i, then there must be no path from j to k (because otherwise there would be a path from j to i). Then k can be moved before j without breaking the validity of the toplogical order. If there has been other vertices between j and i which are moved before j, then moving k right before j would keep the orginal preceding relationship between them. If there are other vertices before k that are not moved, for any such k', since there is no path from k' to i, then there is no path from k' to k (because otherwise there will be a path from k' to i), then k can also be moved in front of k' without breaking the validity of the toplogical sort. Since each step of the above procedure keeps the validity of the toplogical sort, we have derived a valid topological sort with this procedure.
Some facts about topological sort的更多相关文章
- 【拓扑排序】【线段树】Gym - 101102K - Topological Sort
Consider a directed graph G of N nodes and all edges (u→v) such that u < v. It is clear that this ...
- topological sort~~~~初学
今天讲了topological sort 问题: 判环:记录入队的点数,若<n则有环,可证: 算法:o(n):queue or stack,而不是o(n^2)枚举 #. 关系运算图(vijos ...
- topological sort
A topological sortof a dag G is a linear ordering of all its vertices such that if G contains anedg ...
- 拓扑排序(Topological Sort)
Graph 拓扑排序(Topological Sort) 假设一个应用场景:你用 C 编写了一个爬虫工具,其中有很多自定义的库:queue.c.queue.h.stack.c.stack.h.heap ...
- 6-16 Topological Sort(25 分)
Write a program to find the topological order in a digraph. Format of functions: bool TopSort( LGrap ...
- [Algorithms] Topological Sort
Topological sort is an important application of DFS in directed acyclic graphs (DAG). For each edge ...
- [MIT6.006] 14. Depth-First Search (DFS), Topological Sort 深度优先搜索,拓扑排序
一.深度优先搜索 它的定义是:递归探索图,必要时要回溯,同时避免重复. 关于深度优先搜索的伪代码如下: 左边DFS-Visit(V, Adj.s)是只实现visit所有连接某个特定点(例如s)的其他点 ...
- Leetcode: Alien Dictionary && Summary: Topological Sort
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
- 拓扑排序 Topological Sort
2018-05-02 16:26:07 在计算机科学领域,有向图的拓扑排序或拓扑排序是其顶点的线性排序,使得对于从顶点u到顶点v的每个有向边uv,u在排序中都在v前.例如,图形的顶点可以表示要执行的任 ...
随机推荐
- js获取 gps坐标
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(pos) { model.address. ...
- hive中实现类似MySQL中的group_concat功能
hive> desc t; OK id string str string Time taken: 0.249 seconds hive> select * from t ...
- JPQL详解
JPA在说jpql之前必须要说一下什么是JPA,否则在后续学习的时候,你会弄混的.JPA是一种规范,什么是规范呢,规范就是一个钥匙可以开这把锁.一般对于规范来说我们都是用接口,如果有人要我们则实现我们 ...
- 【转】每天一个linux命令(40):wc命令
原文网址:http://www.cnblogs.com/peida/archive/2012/12/18/2822758.html Linux系统中的wc(Word Count)命令的功能为统计指定文 ...
- FineUI 选中多行获取行ID
http://www.fineui.com/bbs/forum.php?mod=viewthread&tid=2506&page=1 /// <summary> ...
- linux raid10管理维护
http://www.linuxidc.com/Linux/2015-10/124391.htm 制作raid10 http://www.linuxidc.com/Linux/2015-09/1 ...
- RedHat Enterprise Linux7.0安装Oracle12c
1. 验证 1.1 硬盘空间要求 1.1.1 安装盘 类型 占用磁盘空间 Enterprise Edition 6.4GB Standard Edition 6.1GB Standard Editio ...
- java枚举使用详解,整理的很好,只能收下。。。
java枚举使用详解 在实际编程中,往往存在着这样的“数据集”,它们的数值在程序中是稳定的,而且“数据集”中的元素是有限的. 例如星期一到星期日七个数据元素组成了一周的“数据集”,春夏秋冬四个数据元素 ...
- wxWidgets:动态EVENT绑定
我们已经看到如何使用静态EVENT TABLE来处理EVENT:但这种方式不够灵活.下面我们来看看如何在Event和处理函数间实现动态Bind. 仍然以那个简陋的Frame作为例子. 首先删除所有的静 ...
- java web程序 String的valueOf方法总集
在代码中用到类型转换的时候,是一个字符,然后当用户在网页中输入的是字符串, 字符转换成字符串的方法是: String.valueOf(char c);就好了 这样在写验证码的时候,网页端的就是字符串形 ...