简体   繁体   English

在无向图中的两个顶点之间的所有简单路径上查找所有*顶点*

[英]Find all *vertices* on all simple paths between two vertices in an undirected graph

Enumerating all simple paths between two vertices in an arbitrary graph takes exponential time in general, because there may be an exponential number of simple paths between the vertices. 枚举任意图中两个顶点之间的所有简单路径通常需要指数时间,因为顶点之间可能存在指数个简单路径。 But what about if we're only interested in the vertices that are on at least one simple path between the two end vertices? 但是,如果我们只对两个端点之间的至少一条简单路径上的顶点感兴趣呢?

That is: Given an undirected graph and two distinct vertices, is there a polynomial-time algorithm which finds every vertex which is on at least one simple path between the two vertices? 那就是: 给定一个无向图和两个不同的顶点,是否有一个多项式时间算法,它找到位于两个顶点之间的至少一条简单路径上的每个顶点? This is not the same as connectivity; 这与连接不同; dead-ends and cul-de-sacs are excluded. 死胡同和死胡同被排除在外。 Branching and joining paths, however, are permissible. 但是,分支和连接路径是允许的。

I've found that it's very easy to write an algorithm which looks like it solves this problem, but either fails in some case, or takes exponential running time in pathological cases. 我发现编写一个看起来像是解决了这个问题的算法非常容易,但在某些情况下要么失败,要么在病态情况下需要指数运行时间。

More generally: Given two disjoint sets of vertices in a graph, is there a polynomial-time algorithm which finds all vertices which lie on a simple path from a vertex in one set to a vertex in the other set? 更一般地说: 给定图中两个不相交的顶点集,是否存在多项式时间算法,该算法找到位于从一个集合中的顶点到另一个集合中的顶点的简单路径上的所有顶点?

(Forgive me if there's a really obvious solution to this. It certainly feels like there should be.) (请原谅我,如果有一个非常明显的解决方案。当然感觉应该有。)

Here is a linear-time deterministic solution. 这是线性时间确定性解决方案。 Inserting an edge between your two end vertices (let's call them a and b), if such an edge doesn't already exist, turns your problem into the problem of finding a maximum set of vertices v that lie on any simple cycle through a and b. 在两个末端顶点之间插入一条边(让我们称之为a和b),如果这样的边不存在,则将问题转化为找到最大的顶点集v的问题,该顶点集位于通过a和湾 You can convince yourself that such a set corresponds to the maximal subgraph containing a and b that cannot be disconnected by removal of any of its nodes (also called biconnected component). 你可以说服自己这样一个集合对应于包含a和b的最大子图,它不能通过删除任何节点(也称为双连通组件)来断开连接。 This page describes the concept and the classic linear-time (DFS-based) algorithm of Hopcroft and Tarjan to identify all biconnected components (you only need the one containing a and b). 本页描述了Hopcroft和Tarjan的概念和经典线性时间(基于DFS)算法,以识别所有双连通组件(您只需要包含a和b的组件)。

Your second question about simple paths between two sets (let's call them A and B) can reduced to the first question by creating a new vertex a with edges to all vertices in A, and a vertex b with edges to all vertices in B, and then solving your first question for a and b. 关于两个集合之间的简单路径的第二个问题(让我们称之为A和B)可以通过创建一个新的顶点a,边缘到A中的所有顶点,以及一个顶点b,边缘到B中的所有顶点,可以简化为第一个问题。然后解决你的第一个问题a和b。

Do you mind a probabilistic solution? 你介意一个概率解决方案吗? That is, it won't guarantee finding all of the vertices, but it usually does first try, and is overwhelmingly likely to after 2 or 3 tries? 也就是说,它不能保证找到所有顶点,但它通常首先尝试,并且绝大多数可能在2或3次尝试之后?

If you're OK with that, randomly assign every edge a resistance, and solve for the voltages of every node if you put the source at a voltage of 1 and the sink at a voltage of 0. Any edge where the two nodes connecting it are at different voltages is clearly on a simple path (the path is easy to construct, just go through ascending voltages from one end, and descending from the other). 如果你没关系,可以随机为每个边沿分配一个电阻,如果你把电源放在电压为1,接收器的电压为0,则求解每个节点的电压。连接它的两个节点的任何边缘在不同的电压下显然是在一条简单的路径上(路径很容易构建,只是从一端经过上升电压,从另一端下降)。 An edge where the two nodes connecting it are at the same voltage is extremely unlikely to be on a simple path, though that theoretically can happen. 连接它的两个节点处于相同电压的边缘极不可能在简单的路径上,尽管理论上可能发生这种情况。

Repeat with several randomly assigned sets of resistances, and you're overwhelmingly likely to have found all edges that are on simple paths. 重复几个随机分配的阻力组,你很可能找到了简单路径上的所有边。 (You haven't proven this answer, but the odds of being wrong are vanishingly small.) (你没有证明这个答案,但错误的可能性很小。)

Of course once you know all of the edges that are on simple paths, it is trivial to get all of the vertices that are on simple paths. 当然,一旦你知道了简单路径上的所有边缘,获得简单路径上的所有顶点都是微不足道的。

Update 更新

I believe that the following is true, but have no proof. 我相信以下是真的,但没有证据。 Suppose that we take a set of resistances and work out voltages. 假设我们采取一组电阻并计算出电压。 For every edge which is in a simple path, there is another edge (maybe the same) such that varying the resistance of only that edge will cause the voltage across the first edge to vary. 对于处于简单路径中的每个边缘,存在另一边缘(可能相同),使得仅改变该边缘的电阻将导致第一边缘上的电压变化。 If so, it is possible in polynomial time to identify every edge in a simple path. 如果是这样,则可以在多项式时间内识别简单路径中的每个边缘。

Intuitively it makes sense to me, but I have no idea how I would prove it. 直观地说,这对我有意义,但我不知道我将如何证明它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM