Details, Explanation and Meaning About Topological sorting

Topological sorting Guide, Meaning , Facts, Information and Description

In graph theory, a topological sort of a directed acyclic graph (DAG) is a linear ordering of the nodes of the graph such that x comes before y if and only if there's a directed path from x to y in the DAG. An equivalent definition is that each node comes before all nodes to which it has edges. Any DAG has a topological sort, and in fact most have many.

Table of contents
1 Examples
2 Algorithms
3 External links

Examples

The canonical application of topological sorting is in scheduling a sequence of jobs. The jobs are represented by vertices, and there is an edge from x to y if job x must be completed before job y can be done. Then, a topological sort gives an order in which to perform the jobs. This has applications in computer science, such as in instruction scheduling, ordering of formula cell evaluation in Microsoft Excel and makefiles.

The graph shown to the left has many valid topological sorts, including:

  • 7,5,3,11,8,2,9,10
  • 7,5,11,2,3,10,8,9
  • 3,7,8,10,5,11,9,2

Algorithms

The usual algorithm for topological sorting has running time linear in the number of nodes plus the number of edges (Θ(|V|+|E|)). It uses depth-first search. First, find a list of "start nodes" which have no incoming edges and insert them into a queue Q. Then,

while Q is nonempty
    remove a node n from Q
    output n
    for each node m with an edge e from n to m
        remove edge e from the graph
        if m has no other incoming edges
            insert m into Q

If this algorithm terminates without outputting all the nodes of the graph, it means the graph has at least one cycle and therefore is not a DAG, so the algorithm can report an error.

External links


This is an Article on Topological sorting. Page Contains Information, Facts Details or Explanation Guide About Topological sorting


Google
 
Web www.E-paranoids.com

Search Anything