计算图中的唯一对(不允许顶点重复)

时间:2014-01-06 10:12:22

标签: algorithm graph

是否存在用于计算undirected graph中唯一对(顶点对)的算法(不允许顶点重复)。我认为它可能是二分图的变体,但如果有更好的方法可以找出...请评论 [我认为问题属于完美匹配算法]
问题陈述: I have an undirected graph which consists of n vertexes and m edges. I can delete edges from the graph. Now I'm interested in one question : is it possible to delete edges in the graph so that the degree of each vertex in the graph will be equal 1.. There can be multiple edges in the graph, but can not be any loops
示例:n = #vertices,m = #edges
n = 4,m = 6
1 2
1 3
1 4
2 3
2 4
3 4
唯一序列可以是(1 2,3 4)(1 4,2 3)(1 3,2 4)

2 个答案:

答案 0 :(得分:1)

覆盖整个图形而不多次使用相同顶点的边集称为匹配独立边集,请参阅wikipedia。< / p>

在该文章中还提到图表中不同匹配的数量(您所追求的数字)称为 Hosoya索引,请参阅this wikipedia article

计算这个数字的算法并不简单,Stack Overflow也不是解释它们的正确位置,但至少我希望你有足够的指针来进一步研究。

答案 1 :(得分:1)

这是伪代码,它应该在O(|E|)时间运行,即边缘数量的线性:

假设G = (V, E)是您的初始图表,E - 所有边的初始集

count = 0;
while(E is not empty) {
    //1. pick up any edge e = (n1, n2) from E

    //2. remove e from G
    E = E - e;

    //3. calculate number of edges in G remaining if nodes n1 and n2 were removed
    // -> these are edges making pair with e
    edges_not_connected_to_e = |E| - |n1| - |n2|;
    // where |n1| - degree of n1 in updated G (already without edge e)

    //4. update the count
    count += edges_not_connected_to_e;
}
return count;

如果您需要更多说明,请与我们联系。也许有人可以修复我的Graph数学符号,以防它们不正确。

相关问题