简体   繁体   English

给定无向图G =(V,E),确定G是否为完整图

[英]Given an undirected graph G = (V, E), determine whether G is a complete graph

我很确定这个问题是P而不是NP,但是我很难提出多项式绑定算法来解决它。

You can : 您可以 :

  1. check that number of edges in the graph is n(n-1)/2 . 检查图中的边数为n(n-1)/2
  2. check that each vertice is connected to exaclty n-1 distinct vertices. 检查每个顶点是否都连接到n-1不同的顶点。

This will run in O(V²) , which is polynomial. 这将在多项式O(V²)运行。

Hope it helped. 希望能有所帮助。

Here's an O(|E|) algorithm that also has a small constant. 这是一个O(| E |)算法,该算法的常数也较小。

It's trivial to enumerate every edge in a complete graph. 枚举完整图形中的每个边都是微不足道的。 So all you need to do is scan your edge list and verify that every such edge exists. 因此,您要做的就是扫描边缘列表,并验证每个这样的边缘是否存在。

For each edge (i, j), let f(i, j) = i*|V| 对于每个边(i,j),令f(i,j)= i * | V | + j. + j。 Assuming vertices are numbered 0 to |V|-1. 假设顶点编号为0到| V | -1。

Let bitvec be a bit vector of length |V| bitvec为长度| V |的位向量 2 , initialized to 0. 2 ,初始化为0。

For each edge (i, j), set bitvec[f(i, j)] = 1. 对于每个边(i,j),设置bitvec[f(i, j)] = 1。

G is a complete graph if and only if every element of bitvec == 1. 当且仅当bitvec每个元素== 1时,G才是完整的图。

This algorithm not only touches E once, but it's also completely vectorizable if you have a scatter instruction. 该算法不仅触及E一次,而且如果您有分散指令,它也可以完全向量化。 That also means it's trivial to parallelize. 这也意味着并行化很简单。

Here is an O(E) algorithm: 这是一个O(E)算法:

  1. Use O(E) as it is input time, to scan the graph 使用O(E)作为输入时间来扫描图形
  2. Meanwhile, record each vertex p's degree, increase degree only if the neighbor is not p itself (self-connecting edge) and is not a vertex q where p and q has another edge counted already (multiple edge), these checking can be done in O(1) 同时,记录每个顶点的度数, 仅当邻居不是p本身(自连接边) 并且不是顶点q(其中p和q已经计算了另一个边数(多个边数)) 时才增加度数,这些检查可以在O(1)
  3. Check if all vertex's degree is |V|-1, this step is O(V), if Yes then it is a complete graph 检查是否所有顶点的度均为| V | -1,此步骤为O(V),如果是,则为完整图形

Total is O(E) 总计为O(E)

For a given graph G = (V,E), check for each pair u, v in the V, and see if edge (u,v) is in E. The total number of u, v pairs are |V|*(|V|-1)/2. 对于给定的图G =(V,E),检查V中的每对u,v,并查看边(u,v)是否在E中。u,v对的总数为| V | *( | V | -1)/ 2。 As a result, with a time complexity of O(|V|^2), you can check and see if a graph is complete or not. 结果,时间复杂度为O(| V | ^ 2),您可以检查并查看图形是否完整。

暂无
暂无

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

相关问题 对于给定的图G =(V,E),您如何在O(E + V)时间中对其邻接列表表示进行排序? - For a given graph G = (V,E) how can you sort its adjacency list representation in O(E+V) time? 给定无向图中完整子图的数量 - Number of complete subgraphs in a given undirected graph 图G的最小顶点覆盖大小为| V |。 -仅当G完成时才为1。 是真的吗 - A graph, G, has a minimum vertex cover of size |V| - 1 if and only if G is complete. Is it true? 对于给定的图 G=(V,E) 和边 e∈E,设计一个 O(n+m) 时间的算法来寻找(如果存在)包含 e 的最短循环 - For a given graph G=(V,E) and an edge e∈E, design an O(n+m)-time algorithm to find, if it exists, the shortest cycle that contains e 确定无向图是否为树 - Determine if an undirected Graph is a tree 给定多图的邻接表,在 O(|V|+|E|) 时间内计算等效(简单)无向图的邻接表 - Given an adjacency list for multigraph, compute adjacency list for equivalent (simple) undirected graph in O(|V|+|E|) time 如果向无向加权图 G 添加新边,则查找 MST T 是否仍然是新图 G' 的 MST - Find if MST T is still a MST for new graph G' if a new edge is added to undirected weighted graph G 您如何确定图G是否具有权重为k的生成树? - How do you determine whether a graph G has a spanning tree of weight k? 确定给定图形是否是其他图形的子图的简单方法? - Easy way to determine whether a given graph is subgraph of some other graph? 令 G=(V, E) 有向图。 设 v 是 G 中的一个顶点,找出参与到 v 的非简单有向路径的顶点数 - Let G=(V, E) directed graph. Let v be a vertex in G, find the number of vertices that take part in non-simple directed paths to v
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM