Happy easters, everyone.
I am currently learning topological sort and having a question about what topological sort tries to really sort.
The Algorithm Design Manual describes topological sort in this way:
Topological sorting is the most important operation on directed acyclic graphs (DAGs). It orders the vertices on a line such that all directed edges go from left to right.
This bold part confuses me. So does the topological sorting sort vertices or all directed edges?
Let’s take an example which is also in the book.

So for the above DAG, we can get a topological sort (G, A, B, C, F, E, D).
I can understand this sort. Not only the vertices are sorted, but the edges are also sorted, i.e., G->A->B->C->F->E->D, this matches the above ADM book description: all directed edges go from left to right
But what if I remove the edge of B->C? The resulting graph is still a DAG, but will the topological sort is still (G, A, B, C, F, E, D)?
If it is Yes, then I think the edges are not sorted, as A->B->C does not exist any more, instead, it is A->B and A->C. So, it this case still a valid topological sort? Can we still
think (G, A, B, C, F, E, D) is a valid sort even if A is the parent of B and C?
Thanks
You can think of it as orderring of elements.
let v1,v2,…,vn be elements. and let an edge
(vi,vj)denote thatvi<vj. topological sort guarantees that after the sorting: for everyvi, and for everyvjsuch thati < j,vjis not greater thenviOr in other notations: assume
(vi,vj)indicate thatvjis dependent onvi, topological sorts guarantees that each element “does not depend” on any elements that appears after it in the sort.topological sort sorts vertices, not edges. It uses edges as constraints for sorting the vertices.
yes, every edge you add, just add a constraint. Note that there could be more then one feasible solution for topological sort [for example, for a graph without edges, any permutation is a feasible solution]. removing a constraint, makes any previous solution, which “solves a harder problem” still feasible.
There is no problem with that! A appears before B,C in the topological sort, so there is no problem it is their father.
Hope that makes it a bit more clear.