1. Topology sequencing

Source: Internet
Author: User

First, the definition

Topological ordering: a sort of vertex with a direction-free graph , which makes the VJ appear behind VI in the sort if there is a path from VI to VJ.

The topological ordering of a direction-free graph G is to arrange all the vertices in G into a linear sequence so that any pair of vertices u and V in the graph, and if the Edge <u,v>∈e (G), the U appears before v in a linear sequence.

Example: In the Learning course map, there is a <c language, data structure, and then the topological sort of the graph, in the resulting linear sequence, C language must be ranked before the data structure.

Second, AOV Network

Introduction: An existing project needs to be completed, we need to make a flow chart of the construction , it can decide which sub-projects must be executed first, which sub-projects to be executed after certain projects. In order to reflect the relationship between the various sub-projects in the whole project, we can use a graph to show that the vertices in the diagram represent the activities (sub-projects), and the forward side of the graph represents the succession relationship of the activities.

Definition: We put this vertex activity, the side represents the relationship between the activities of the graph called the vertex activity network, referred to as AoV network.

A AOV network should be a direction-free graph, that is, should not have a loop, because if there is a loop, then all the activities on the loop can not be carried out (for the data flow is a dead loop).

In the AOV network, if there is no loop, then all activities can be arranged into a linear sequence, so that all precursor activity of each activity is in front of the activity, we call this sequence topological sequence, the process of constructing topological sequence by AoV Network is called topological sort.

Note: The topology sequence may not be unique, and the AOV network must be non-circular, because only a forward-free graph can form a topological sequence.

Third, the algorithm process

    1. Select a vertex without a precursor in the graph and output
    2. Delete the vertex and all the arcs that end with it (the vernacular is: delete all sides related to it)
    3. Repeat these two steps until all vertices are output, or the current graph does not have a non-precursor vertex, the latter represents our forward graph is ring, so you can also use topological sort to determine whether a graph has a ring.

is a AOV network that requires topological ordering of it.

(1) We found that V6 and V1 are not precursors, so we randomly selected a output, we first output V6, delete and V6 about the edge, get as the result:

(2) We continue to look for vertices without precursors and find V1 without precursors, so output V1, delete and V1 related edges, get results:

(3) We found that V4 and V3 are not precursors, then we randomly select a vertex output (specific to your implementation of the algorithm and graph storage structure), we output V4, get as the result:

(4) We output a vertex V3 without a precursor, and we get the following result:

(5) We output V5 and V2 respectively, when all vertex output is complete

A sequence of topologies for the graph is: V6---> V1---> V4---> V3---> V5---> V2

1. Sort by topology

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.