12

I am looking for an algorithm to convert a digraph (directed graph) to an undirected graph in a reversible way, ie the digraph should be reconstructable if we are given the undirected graph. I understand that this will come in expense of the undirected graph having more vertices but I do not mind.

Does one know how to do this or can suggest any references? Thanks in advance.


Update: Regarding the answer of AdrianN below. It might be a good starting point but I don't think it works in its current form. Here is an image of why I think it doesn't: enter image description here


Update after D.W.'s comment: I consider the vertices of the graphs to be unlabeled. If a solution involves labeling the vertices (like AdrianN's does), then it should give the same (isomorphic) undirected graph no matter how the labeling is done. My definition of "isomorphic" for graphs with labeled vertices is that there is a permutation of the labeling that relates the two graphs, but I am not sure of the exact definition for unlabeled graphs...

Heterotic
  • 391
  • 1
  • 2
  • 12

5 Answers5

10

David Richerby's answer (which was accepted) is good.

I followed his instructions on a simple example digraph, and hope it helps someone.

digraph a <-> b, c -> a, b -> c

(I would have posted this as a comment on David's answer, but I do not have the reputation points required.)

William
  • 201
  • 2
  • 5
8

For each directed edge $e=(x,y)$, add new vertices $v^e_1, \dots, v^e_5$ and replace $e$ with the edges $xv^e_1$, $v^e_1v^e_2$, $v^e_1v^e_3$, $v^e_3v^e_4$, $v^e_4v^e_5$, $v^e_3y$.

To decode, every leaf (degree-1 vertex) whose neighbour has degree 2 must be $v^e_5$ for some edge $e=(x,y)$; its neighbour is $v^e_4$ and the other neighbour of $v^e_4$ is $v^e_3$. $v^e_3$ has a unique neighbour that has both degree 3 and is adjacent to a leaf: the neighbour is $v^e_1$ and its leaf is $v^e_2$ (if $v^e_1$ has two leaf neighbours, pick one arbitrarily to be $v^e_2$). The other neighbour of $v^e_1$ is $x$ and the other neighbour of $v^e_3$ is $y$. Restore the directed edge $(x,y)$ and delete the vertices $v^e_1, \dots, v^e_5$.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
2

To convert a directed graph $D$ to an undirected graph $G$ one do the following:

  1. Number the nodes of $D$
  2. Create two undirected graphs $G'$, $G''$ on the same vertex set as $D$
  3. For every edge $u$,$v$ in $D$ add the edge to $G'$ if $u<v$, else add the edge to $G''$
  4. G is the disjoint union of $G'$ and $G''$

When doing the disjoint union one must take care to make it reversible.

Example

adrianN
  • 5,991
  • 19
  • 27
-1

What about the identity function ? I.e. every digraph can be seen as a undirected, bipartite graph with equal sized partitions and vice versa.

muede
  • 19
  • 1
-1

Here's a stab at this:

Replace the direction information with additional vertices in the undirected graph. In other words, use the additional vertices in the undirected graph to "encode" the direction information. For example, for each directed vertex with at least one edge, add a number of undirected vertices equal to 1 + the number of "incoming" edges. Vertices with zero edges remain unchanged.

To perform the reverse direction, create a directed vertex for each vertex that has 0 or more than 1 edge. (Vertices with exactly one edge are the "direction encoding" vertices). Each edge that connects another multi-edged vertex is a connection in the directed graph. Now is the tricky part that I can't explain an algorithm for (but I think one exists): You must deduce the direction of the arrows given only the number of incoming arrows for each vertex.

I think the tricky part is sort of like playing minesweeper :-) Figure out where the bombs (incoming edges) are given the number of adjacent bombs for each square (vertex).

Aaron
  • 131
  • 2