Topological Sort (briefly)

Topological sorting is a more commonly used graph theory algorithms, often have dependencies used to complete the task of sorting.
For chestnut: Some people want to make a tool, but this tool is not the time to be completed, divided into many steps, and these steps are sequential, that is, assuming that the order of B of A's in the back, then you we must first complete a complete re-B, but also some steps, regardless of the order, which means you do first is possible.


Faced with this problem, we can step into establishing a directed acyclic graph, A to point B means A is to be completed in front of B, then the following, we will find a sequence, the answer to meet the subject requirements . Topological sorting is to do such a thing.

Topological Sort realization of ideas: start with the first node is not the start of penetration (if there is more then any), this point in the queue, and delete relating edges above steps are repeated until all points all queued, this time can be output.

 

Guess you like

Origin www.cnblogs.com/wizarderror/p/11311082.html