I\'m looking for an algorithm which can diff
two Directed Acyclic Graphs(DAGs). That is, I\'d like an algorithm which produces a sequence of deletions and insertion
How would your specific data representation show that edges c
and x
in your DAG 2 example terminate in the same vertex?
If we assume Wikipedia's general definitions of "directed graph", "vertex", and "edge", there is no such thing as an "unlabeled vertex" because without labeling them, there would be no way to describe edges, according to the definition there.
As is, it seems to me your question is impossible to answer. Please provide (1) a simple example of the input provided to the algorithm — a data structure describing each graph as a collection of vertices and edges — and the expected output in a similar way, and (2) a consistent way to distinguish if an edge or vertex in the first DAG is equivalent to one in the second DAG, implying no difference in that aspect of the graphs.
Perhaps your question is actually mostly about how to determine the labels for the vertices in each DAG in the input and how to best correlate them. Or, alternatively, perhaps labels are just a convenience to describe each graph and the question is actually seeking the minimal set of changes to describe a transformation of the structure of one graph to another.
That said, edges and vertices in a traditional, mathematical, definition of a graph are atomic. Each vertex or edge either exists or does not exist in any one graph, making the concept of a diff somewhat meaningless, or otherwise trivial to build, if we assume that an identical label for any specific vertex or edge represents the exact same vertex or edge in both graphs.
Such a trivial algorithm would basically just enumerate each vertex and edge in the two DAGs and add the appropriate operations to the diff, choosing only from the following operations:
add vertex v
remove vertex v
add edge e
remove edge e
switch direction for edge e