python - Optimizing K_ij-free Subgraph Detection in a Bounded-Degree Graph - Stack Overflow

I am working with an undirected graph G where the maximum degree is bounded by a constant d. My goal is

I am working with an undirected graph G where the maximum degree is bounded by a constant d. My goal is to check whether G contains a complete bipartite subgraph K_{i,j} as a subgraph, for small values of i, j (specifically, i, j < 8).

I currently use the following brute-force approach to detect a K_{i,j} subgraph:

nodes = [u for u in self.g if len(self.g[u]) >= j]
set_combinations = combinations(nodes, i)
for A in set_combinations:
  common_neighbors = set(self.g)
  for u in A:
    common_neighbors &= self.g[u]
    if len(common_neighbors) >= j:
      return False # K_ij found
  return True

This method works correctly but becomes slow as the graph size increases. The main bottleneck seems to be:

  • Enumerating all subsets of i nodes (O(n^i) complexity).
  • Intersecting neighbor sets iteratively, which can be costly for large graphs.

Given that the maximum degree is bounded and i, j are small, I wonder if there are more efficient approaches.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743758966a4502269.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信