----------topology Sorting--------------

Source: Internet
Author: User

Topological sorting

Topological order: If there is a forward path from V to W in the figure, V must precede w. The sequence of vertices that satisfy this condition is called a topological order.

The process of obtaining a topological order is the topological ordering

A sequence is obtained after the topology is sorted

Each time we want to output a node without a precursor vertex, that is, a point with no degree of penetration. After the output, set the vertex to 0

AOV (Activity on vertex Network) if there is a reasonable topological order it must be a directed acyclic graph (Directed acyclic graph, DAG)

V must end before the start of v,,,, obvious error,,, so a reasonable topological order cannot exist ring.

voidTopsort () { for(cnt=0; cnt<v;cnt++) {V= a vertex with an input level of 0 not being output;//This step is discussed below.        if(Such a v does not exist) {Error ("There is a circuit in the diagram");  Break; } output V, or record the output sequence of V for(V for each pro contact W) Indegree[w]--;//a reduction of V so that the penetration of each of the pro contacts will be reduced by one.    }}

The first solution is to iterate over the time complexity to n^2.

The second solution is to put the degree of entry into a different container at any time by turning it into 0. Time complexity is a constant number of levels

The second method uses the queue when the code is as follows

voidTopsort () { for(each vertex on the way V)if(indegree[v]==0) Enqueue[v,q];  while(!IsEmpty (Q)) {V=Dequeue (Q);        Output V, or record the output serial number of V.  for(V for each pro contact W) {if(--indegree[w]==0) Enqueue[w,q]; }    }    if(the number of vertices not enough to output) Error ("There is a circuit in the diagram");}

AOE (Activity on Edge) network

Critical path Issues

AOV

----------topology Sorting--------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.