Does anyone know an efficient algorithm to compute a line digraph from a digraph? See http://en.wikipedia.org/wiki/Line_graph (The Wikipedia article mentions the digraph case near the bottom (in the Generalizations sections). Ideally I would like to do this in linear time.
From that section:
- If G is a directed graph, its directed line graph or line digraph has one vertex for each edge of G.
- Two vertices representing directed edges from u to v and from w to x in G are connected by an edge from uv to wx in the line digraph when v = w.
Let G be the directed graph Let L(G) be the directed line graph
The algorithm I can come up with to produce L(G) given G is:
- Iterate through all edges of G to produce the nodes of L(G)
- Iterate through all pairs of nodes (uv, wx) in L(G) and connect if v = w
This is an O(n^2) algorithm.
Seems like there should be a way to get this down to O(n) time. I'm going to go think about this, but I figured I'd ask stack overflow just in case there's some famous (or not so famous) algorithm for doing this that I don't know of.