User:Khurram231

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.

Algorithm
The algorithm of Pearce and Kelly, 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 [4]. 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 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
1:The “sort” function sorts an array such that x comes before y iff ord[x] < ord[ y]. 2:“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 ify reaches x

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.

Proof of correctness
Give a high-level intuitive explanation why the algorithm works. You don't need to be technical (it shouldn't be technical), but try to explain it in such a way that a reader would be convinced that the algorithm indeed does what it supposed to do.

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.

Variations
Describe variations of the algorithm you are doing (if any). For example, Kruskal's algorithm variation is when edges are considered in descending order.

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.

Other material
There are other sections you might want to add, depending on your problem. For example, you might have a section describing implementations of your algorithm -- especially if there are interesting ones, e.g. in parallel setting.