4

Imagine I have a weighted complete directed graph $G$ with $d$ vertices(so $d(d-1)$ edges) and I want to do the following:

  1. Set $D$ to be a DAG with the same set of vertices but without any edges
  2. sort the edge weights $c_{ji}$ of the original graph by size
  3. From the biggest to the lowest edge weight: Add an edge $(j,i)$ to the DAG $D$ if we do not cause a cycle with it

Now I see two approaches to implement this.the first one is:

  1. Set $D$ to be a DAG with the same set of vertices but without any edges
  2. sort the edge weights $c_{ji}$ of the original graph by size
  3. From the biggest to the lowest edge weight: Add an edge $(j,i)$ to the DAG $D$ if there is no path from $i$ to $j$

Now sorting can be neglected in complexity ( $O(d^2\log(d))$)

And number three is performed at most $d(d-1)$ times and to check if a path exists we can use BFS or DFS and the number of edges, unfortunately, can be as big as $d^2$ so we have $d^4$ in total

My second idea: Work with a reachability matrix and update the reachability matrix in every iteration of the loop... But then updating the reachability matrix is again of complexity $d^2$ because if we set an edge from $j$ to $i$ then denoting the ancestors of $j$ by $k_1$ and the descendants of $i$ by $k_2$ we need to set $R(u,w)=1$, $R(u,i)=1$, $R(j,w)=1$ for any $u$ in $k_1$ and $w$ in $k_2$ .... Assuming that in the worst case that each of $k_1$ and $k_2$ have $d/2-1$ vertices we get a complexity of $d^2$ That we need to update the reachability matrix more than $O(d)$ times can e.g. be seen by looking at bipartite graphs... So I'm again stuck with the same complexity... Is there actually a more efficient solution?

Johannes
  • 71
  • 4
  • 4
    The bottommost link in this excellent answer to a similar question promises to make adding edges to a DAG and checking for connectivity both amortised $O(d)$-time operations, bringing the overall complexity down to $O(d^3)$. – j_random_hacker Mar 27 '19 at 15:54
  • For undirected graphs, this algorithm is called Kruskal's algorithm and returns the minimum spanning tree. But a different algorithm must be used for MSTs in directed graphs. Is that what you're attempting to find, or do you really want the "almost MST" graph returned by this algorithm? – BlueRaja - Danny Pflughoeft Mar 27 '19 at 16:50
  • @j_random_hacker I am just reading the paper but if it is true what it says(what I of course assume it does) it seems like it indeed reduces the complexity to $O(d^3)$ - which is awesome... Thank you so much! – Johannes Mar 27 '19 at 18:41
  • @BlueRaja - what do you mean? It is indeed similar to Kruskal but the algorithm also is: Kruskal does the following: Sart with the isolated graph and add the smallest edge if it is not already added; Now I do basically the same: Start with an isolated graph and add the edge of biggest value in case it does not create a cycle; But interesting is that the running time of Kruskal is only $O(E \log(V))$ which is better than $O(d^3)$ - so the question is if there is even more room for improvement – Johannes Mar 27 '19 at 19:04
  • I suspect that this probably is not possible because: When I have Kruskal then I add $d-1$ edges to the spanning tree; This, however, is not valid here: Imagine I add an edge if and only if there is no path between the two vertices already; Then we can consider e.g. a bipartite graph; Imagine I have two disjunct sets of nodes $m_1$ and $m_2$, each having $d/2$ nodes; Then I can add any edge from $u$ to $v$ for $u$ in $m_1$ and $v$ in $m_2$, so I can add $d^2/4$ many edges - so a huge difference to Kruskal - thats why I think $O(d^3)$ is hard to beat - @j_random_hacker What do you think? – Johannes Mar 27 '19 at 19:15
  • Glad it was helpful :) Indeed it seems that these "dynamic connectivity" problems are very difficult, and an ongoing area of research. There is an even worse example of a cycle-free digraph: number all vertices from 1 to $n$, and create an edge $uv$ whenever $u > v$. – j_random_hacker Mar 27 '19 at 19:23
  • 2
    @Johannes This method does not necessarily produce a MST analogue for directed, weighted graphs, as the edgeweight of the resulting acyclic graph needn't be maximal. Are you sure you don't want it to be maximal? – Sudix Mar 27 '19 at 19:37
  • First of all: Sorry for the many flaws I did when writing the previous comments: E.g. I mean of course: "It is indeed similar to Kruskal and the algorithm also is: Kruskal does the following: Sart with the isolated graph and add the smallest edge if it does not create a cycle" @j_random_hacker: I did not think of the most trivial solution: A complete DAG, how stupid of me; – Johannes Mar 27 '19 at 20:01
  • @Sudix: You are right, it does not need to be maximal; If we want it to be maximal we end up with the Linear Ordering Problem which is known to be NP-hard (so you will anyway find no polynomial-time algorithm unless P=NP) – Johannes Mar 27 '19 at 20:01
  • 3
    My (and @Sudix's) point was that you appear to be looking for the MST, but this algorithm only does that for undirected graphs. If so, it's not NP-hard. Chu-Liu's algorithm solves it in $O(d^3)$ – BlueRaja - Danny Pflughoeft Mar 27 '19 at 20:37
  • 1
    You are talking about Optimum branching I assume... of course the solution I am talking about is not a solution for the optimal branching because in my case I can get a complete DAG whereas Optimum branching I have $d-1$ edges - but thank you very much for this remark – Johannes Mar 27 '19 at 21:20

0 Answers0