9

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!

copumpkin
  • 2,836
  • 18
  • 25
  • 4
    This paper, [Faster Algorithms for Incremental Topological Ordering](http://www.cs.princeton.edu/~sssix/papers/dto-conf.pdf), claims an **amortized** O(m^1/2) per arc addition. Not sure if that's good enough, or if a worst-case bound is possible. I haven't read beyond the introduction. – Crosbie Oct 26 '11 at 19:02

1 Answers1

1

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).

mitchus
  • 4,677
  • 3
  • 35
  • 70