一种从有向图计算线有向图的有效算法

发布于 2024-07-24 07:59:04 字数 604 浏览 8 评论 0原文

有谁知道从有向图计算线有向图的有效算法? 请参阅 http://en.wikipedia.org/wiki/Line_graph (维基百科文章提到底部附近的有向图情况(在“概括”部分中)理想情况下,我想在线性时间内完成此

操作:

  • 如果 G 是有向图,则其有向线图或线有向图 G 的每条边都有一个顶点。
  • 向边的两个顶点通过线图中从 uv 到 wx 的边连接。

当 v = w 时,表示 G 中从 u 到 v 和从 w 到 x 的有 设 L(G) 为有向线图

给定 G 时,我可以想出生成 L(G) 的算法是:

  • 迭代 G 的所有边以生成 L(G) 的节点
  • 迭代所有节点对 (uv , wx) 在 L(G) 中并在 v = w 时连接

这是一个 O(n^2) 算法。

似乎应该有一种方法可以将其降低到 O(n) 时间。 我要去考虑这个,但我想我会问堆栈溢出,以防万一有一些我不知道的著名(或不那么著名)算法来执行此操作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写给空气的情书 2024-07-31 07:59:04

你不能逃避 O(n^2),因为有一些图具有线性图,其边的基数等于原始图的顶点基数的平方:例如,想一想,在具有 n+1 个顶点的图,其中一个顶点连接到其他所有顶点:然后您必须构建一个具有 n 个顶点的团,因此具有 (n-1)^2 条边。

算法的复杂性自下而上受其产生的输出大小的限制。

当然,这并不意味着我们不必寻找智能算法。 我曾经这样想过:

LG(LN,LE) getLinearGraph(G(N,E)) {
  LN = EmptySet();
  LE = EmptySet();
  for (Vertex v : N) {
    verticesToAdd = EmptySet()
    for (Vertex i : out-degree(v) {
      toAdd += textual-rep((v,i));
    }
    LN += toAdd;
    LE += make-clique(toAdd);
  }
}

You can't exape from O(n^2), because there are some graph with a linear graph with a cardinality of the edges equals to the square of the cardinality of the the vertices of the original one: think, for example, at a graph with n+1 vertices, with a single vertex connected to other all vertices: you have then to build a clique with n vertices, so with (n-1)^2 edges.

The complexity of an algorithm is bounded from the bottom by the size of the output it produces.

This, of course, doesn't mean we don't have to find smart algorithms. I've thinked at that:

LG(LN,LE) getLinearGraph(G(N,E)) {
  LN = EmptySet();
  LE = EmptySet();
  for (Vertex v : N) {
    verticesToAdd = EmptySet()
    for (Vertex i : out-degree(v) {
      toAdd += textual-rep((v,i));
    }
    LN += toAdd;
    LE += make-clique(toAdd);
  }
}
悸初 2024-07-31 07:59:04

嗯...我认为经过一番思考后可能会有一种更省时的算法...但它需要大量的簿记和大量的额外内存才能做到这一点。

我的基本想法是循环 G 中的所有节点,并从连接到每个节点的边创建连接的节点。 通过额外的链接来跟踪 G(边)到 L(G)(节点),您可能只需通过 G 上的节点进行一次循环即可摆脱困境。

Hmm... I think there may be a more time-efficient algorithm after some thought too... but it would require a fair amount of book-keeping and a chunk of extra memory to do so.

My basic thoughts are that you loop over all the nodes in G and create connected nodes from the edges connected to each node. With an extra link to keep track of G(edge) to L(G)(node) you may be able to get away with just one loop through the nodes on G.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文