Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a data structure for DAGs that supports efficient edits?

I'm looking for a data structure that will store any DAG, but can efficiently (i.e., sub-linearly in the number of edges/vertices) detect if adding an edge would create a cycle (and thus prevent you from breaking the acyclic invariant). Does anyone know of such a thing?

Thanks!

like image 321
copumpkin Avatar asked Oct 25 '11 17:10

copumpkin


People also ask

What is a DAG data structure?

A DAG is an information or data structure which can be utilized to demonstrate diverse problems. It is an acyclic graph in topological ordering. Each directed edge has a certain order followed by the node. Every DAG starts from a node that has no parents and end with one that has no kids.

Can DAGs have loops?

Since a DAG is defined by Python code, there is no need for it to be purely declarative; you are free to use loops, functions, and more to define your DAG.

How DAG is useful in data flow analysis?

The Directed Acyclic Graph (DAG) is used to represent the structure of basic blocks, to visualize the flow of values between basic blocks, and to provide optimization techniques in the basic block.

Can DAG have cycles?

In mathematics, particularly graph theory, and computer science, a directed acyclic graph (DAG) is a directed graph with no directed cycles.


1 Answers

You could maintain a datastructure about the graph's transitive closure. Then checking whether adding an edge causes cycles is done in constant time; if you want to add edge (i,j), check if there is already a path from j to i. However, updating the datastructure could be more costly in general (see e.g. La Poutré and van Leeuwen).

like image 175
mitchus Avatar answered Nov 02 '22 08:11

mitchus