简体   繁体   English

图论-当一个节点的所有边都包含在一个循环中时

[英]Graph theory - when all edges of a node are contained within a cycle

Given a directed or undirected graph, there are many algorithms to find cycles. 给定有向图或无向图,有很多算法可以找到循环。 However, I am looking for a specific type of cycle. 但是,我正在寻找一种特定类型的循环。 A cycle in which a node [0...n] in my graph, which has "k" outward edges, has all k of it's edges contained to that cycle. 一个循环,其中我的图形中的节点[0 ... n]具有“ k”个向外边缘,该循环包含所有k个边。 That is to say, all of the edges of our node only connect to other nodes that make up the cycle. 也就是说,我们节点的所有边缘仅连接到构成循环的其他节点。

Example: 例:

We have a cycle (in an undirected graph, this time): ABDECA 我们有一个周期(这次是在无向图中):ABDECA

In my matrix, node B has the following edges: 在我的矩阵中,节点B具有以下边缘:

BA, BE, BD BA,BE,BD

This cycle qualifies as the type of feature I am looking for. 此周期符合我要寻找的功能类型。

It is not required that every node in the cycle meet this rule- it is only required that at least one node in the cycle meets the rule. 不需要周期中的每个节点都符合此规则-仅要求周期中的至少一个节点都符合规则。

So my question is - is there a name for this type of feature? 所以我的问题是-这种功能有名称吗? And, is there an algorithm or does anyone even have a suspicion that an algorithm could be made to find such features more efficiently than randomly searching for cycles and then checking if any of their nodes meet the rule? 而且,是否存在一种算法,或者甚至没有人怀疑可以使一种算法比随机搜索周期然后检查其任何节点是否符合规则更有效地找到这些特征?

You can find all the cycles in a component of a graph by doing a DFS and finding all back edges (eg here ). 您可以通过执行DFS并找到所有后边缘(例如here )来找到图形组件中的所有循环。 This is an O(n + m) operation. 这是O(n + m)运算。

In the worst case, you could build a hash table (set) of all the nodes in the cycle and just check the connections of every node against it. 在最坏的情况下,您可以为循环中的所有节点构建一个哈希表(集合),然后仅对照该节点检查每个节点的连接。 There is no additional cost to building the hash table in terms of complexity, since you can do it while you unwind the stack that created the cycle and insertions are O(1), but checking against it may be expensive since the number of edges per node is indeterminate. 就复杂度而言,构建哈希表没有额外的成本,因为您可以在展开创建循环的堆栈且插入为O(1)的同时进行此操作,但由于每条边的数量多,对其进行检查可能会很昂贵节点不确定。 You can probably filter out a significant number of candidates immediately by marking their connections as you go. 您可以通过标记您的联系来立即过滤掉大量候选人。 I can not think of a fast algorithm to do this at the moment, but I will revisit this question when I do. 我目前无法想到一种快速的算法来执行此操作,但是当我这样做时,我将重新讨论该问题。

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

相关问题 使用 networkx 图中的数据获取链接到给定节点的所有边 - Get all edges linked to given node with data in networkx graph 获取链接到 networkx 图中给定节点的所有边 - Get all edges linked to a given node in a networkx graph 在python的加权图中查找所有负周期和正周期的代码? - Code for finding all negative and positive cycle within weighted graph in python? 为图形边缘传递节点颜色时的运行时错误 - Runtime error when passing node colors for graph edges 在十亿个节点的无向​​图中无循环地从正好k个边的源节点中找到目标节点的算法/方法 - Algorithm/Approach to find destination node from source node of exactly k edges in undirected graph of billion nodes without cycle 遍历图中所有边的算法 - Algorithm to traverse all edges in a graph 查找图上所有边的路径 - Finding the Path of all Edges on a Graph 我如何在这个简单的图中找到某个节点的所有传入弧/边 - How do i find all incoming arcs/edges of a certain node in this simple graph 图论DFS获取从起点到终点的路径 - graph theory DFS get the path from start to end node 是否可以在图论中为节点添加权重/概率(使用networkx) - Is it possible to add a weight/probability to a node in graph theory(using networkx)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM