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的更多相关文章

  1. 【拓扑排序】【线段树】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 ...

  2. topological sort~~~~初学

    今天讲了topological sort 问题: 判环:记录入队的点数,若<n则有环,可证: 算法:o(n):queue or  stack,而不是o(n^2)枚举 #. 关系运算图(vijos ...

  3. topological sort

    A topological sortof a dag G  is a linear ordering of all its vertices such that if G contains anedg ...

  4. 拓扑排序(Topological Sort)

    Graph 拓扑排序(Topological Sort) 假设一个应用场景:你用 C 编写了一个爬虫工具,其中有很多自定义的库:queue.c.queue.h.stack.c.stack.h.heap ...

  5. 6-16 Topological Sort(25 分)

    Write a program to find the topological order in a digraph. Format of functions: bool TopSort( LGrap ...

  6. [Algorithms] Topological Sort

    Topological sort is an important application of DFS in directed acyclic graphs (DAG). For each edge ...

  7. [MIT6.006] 14. Depth-First Search (DFS), Topological Sort 深度优先搜索,拓扑排序

    一.深度优先搜索 它的定义是:递归探索图,必要时要回溯,同时避免重复. 关于深度优先搜索的伪代码如下: 左边DFS-Visit(V, Adj.s)是只实现visit所有连接某个特定点(例如s)的其他点 ...

  8. Leetcode: Alien Dictionary && Summary: Topological Sort

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  9. 拓扑排序 Topological Sort

    2018-05-02 16:26:07 在计算机科学领域,有向图的拓扑排序或拓扑排序是其顶点的线性排序,使得对于从顶点u到顶点v的每个有向边uv,u在排序中都在v前.例如,图形的顶点可以表示要执行的任 ...

随机推荐

  1. HDU1070:Milk

    Milk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. springboot项目文件上传(绝对路径)并使用tomcat虚拟路径进行图片预览

    前言 项目中,需要上传文件,但是可能会比较多,所以不能放入项目目录中,需要指定目录并按顺序放置.并且:还需要这些数据可以预览(图片等). 那么问题就是:上传完成之后我存入服务器,并拿到绝对路径,存入数 ...

  3. V4L2 subdev

    除了通过v4l2_subdev_ops结构体暴露kernel API,V4L2 sub-devices也可以被用户空间应用直接控制.v4l-subdevX的设备节点可以在/dev下被创建来直接访问su ...

  4. solr 6.2.1环境搭建

    一:Solr简介 Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过 ...

  5. sql 变量赋值

    mysql 的变量赋值如下: set @name='app' ; or set @name:='appfirst'; or with select select @appname:='you name ...

  6. storm之 Storm 工作原理

    Storm 工作原理 Storm简介 1.Storm是一套分布式的.可靠的,可容错的用于处理流式数据的系统. 2.Storm也是基于C/S架构来进行工作的,C负责将数据处理的方式的jar(Topolo ...

  7. 一个经典的PHP加密解密算法

    项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理.最常见的应用在用户登录以及一些API ...

  8. 51nod 1673 树有几多愁——虚树+状压DP

    题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1673 建一个虚树. 一种贪心的想法是把较小的值填到叶子上,这样一个小值限制到的 ...

  9. Angular 4 投影

    1.创建工程 ng new demo4 2. 创建子组件 ng g component child 3.子组件html定义 <div class="wrapper"> ...

  10. struts中指定编码(使用Filter后仍然乱码)

    https://www.cnblogs.com/oldinaction/p/5167481.html 概述: Tomcat默认是 ISO编码,不支持中文.尝试过自己写 Filter,在web.xml中 ...