User:KSDTS

Dynamic Topological Sorting is the problem of updating a topological sort of some graph after a new edge has been inserted. For a directed acyclic graph, a topological sort is a linear ordering of the nodes of the graph, such that node x comes before node y if there exists a directed edge x->y in the graph. Dynamic topological sort algorithms are generally divided into two categories. Those which restore the sort after just one invalidating edge has been added are known as unit change algorithms. Algorithm which restores the sort after multiple invalidating edges have been added. These are known as batch algorithms. This are different algorithms which are used to maintain the Dynamic topological sort of DAG graph.We analyse the algorithm of Pearce and Kelly[1] for unit change in graph.

Algorithm
The algorithm of Pearce and Kelly[1], is known as the PK algorithm, which has been shown to work well in practice, and in fact better than any other known algorithm on sparse graphs [3]. For an invalidating edge x→y, the algorithm works by considering all the nodes between x and y which either reach x or are reachable from y.The nodes which reach x are shifted left along with x itself, and the nodes reachable from y are shifted right along with y itself. This is done in such a way that x now comes before y in the topological sort, and the edge x→y is no longer invalidating. The nodes to be rearranged are placed back into the positions they occupied before, but with a new order. The PK algorithm does more work in traversing the graph than the MNR(mentioned in relative work section) algorithm, since it finds both the nodes reachable from y and the nodes that reach x. However it does less work in moving nodes, since nodes in the affected region on either a path from y or to x will not be moved. For sparse graphs (graphs with few edges relative to the number of nodes), the this algorithm will move a lot less nodes than the MNR algorithm, because the low number of edges in a sparse graph means that nodes are less likely to be on a path with either x or y.

Example


Above diagram show the how the PK algorithm works to restore a topological sort, given an invalidating edge x→y. 2nd pic shows the sort after nodes discovered via the backward search from x have been removed, and stage 3 shows the sort after nodes discovered via the forward search from y have been removed. nodes are not moved if they are neither reachable from y nor reaching x.

Pseudocode
The sort function sorts an array such that x comes before y iff ord[x] < ord[ y]. and “merge” combines two arrays into one while maintaining sortedness (i.e., merge sort). Cycles need only be checked for in dfs-f, since an invalidating edge x → y can only give rise to a cycle if y reaches x.


 * &+xy :For an invalidating edge x→y, this is the set of nodes within the affected region reachable from y.
 * &-xy :For an invalidating edge x→y.this is the set of nodes within the affected region that reach x.
 * &xy :For an invalidating edge x→y.


 * 1) procedure add_edge(x,y)
 * 2) lb=ord[y];
 * 3) ub=ord[x];
 * 4) if lb w belong E do
 * 5) if ord[w] =ub then abort//cycle
 * 6) if visited(w) intersection ord[w] n belong E do
 * 5) //is w unvisited and in effected region?
 * 6) if visited (w) ib< ord [w] then dfs-b(w)
 * 1) procedure reorder
 * 2) //sort sets to preserve original order of elements
 * 3) Sort($Bxy)
 * 4) sort($Fxy)
 * L=0
 * 1) //Load $Bxy into Array L first
 * 2) //Load $Fxy into Array L first
 * 3) Merge($Bxy,$fxy,R)
 * 4) //allocate vertices in L starting from lowest

Complexity
Dynamic topological sorting algorithm being based on the standard topological sorting algorithm. Such an algorithm would need to revisit all the nodes and edges in the graph for every edge insertion. In other words, the standard algorithm has a complexity of O(V + E), where V is the number of nodes in the graph and E is the number of edges. This has the potential to be very inefficient, since the number of possible edges.

Applications
A directed acyclic graph is perhaps most commonly used to represent dependencies between nodes, where nodes represent some kind of unit in a system, and edges represent the dependencies. A node may represent a task, and the incoming and outgoing edges for that task connect it with other tasks which must be completed either before or after it. Many situations in the real world can also be represented as directed acyclic graphs, such as traffic flow, aeroplane schedules, task scheduling, and so on. All of these problems could potentially benefit from dynamic topological sorting algorithms.

Related algorithms
A number of previous algorithms have been developed to solve the dynamic topological sorting problem. One example is the algorithm of Marchetti-Spaccamela et al, henceforth referred to as the MNR algorithm [3]. For an invalidating edge x→y, the MNR algorithm removes y and all the nodes between x and y which are reachable from y. The nodes remaining are moved down the topological sort to make space after x in the topological sort. The nodes that were removed are then placed in this space to complete the sort.

There is a algorithm by Alpern et al, That is known as the AHRSZ algorithm[2]. This algorithm works rather differently to maintains a topological ordering and not a topological sort. Whereas a topological sort is implemented as a total ordering, a topological ordering need only be a partial ordering, since more than one node can have the same priority. For an invalidating edge x→y, the algorithm does a frontier search along both the nodes reachable from y with the lowest priorities and the nodes that reach x with the highest priorities. The algorithm favours visiting nodes reachable from y with a lower out-degree and nodes that reach x with a lower in-degree. When the frontiers meet, the algorithm then moves the nodes it has discovered in the priority space to restore the sort. An interesting fact about the algorithm is that it is shown to move the minimal number of nodes necessary to restore the ordering [4]. This minimal set of nodes is known as the minimal cover, Kmin.