确定图表是否具有不使用DFS的循环(Determining if a graph has a cycle without using DFS)

编程入门 行业动态 更新时间:2024-10-23 07:34:43
确定图表是否具有不使用DFS的循环(Determining if a graph has a cycle without using DFS)

我在考试中遇到了其中一个问题:

使用Kahn算法进行拓扑社会排序要求图形为DAG(有向无环图)。 如何在不首先使用DFS / BFS的情况下确定图形是否不包含循环?

我现在试图回答这个问题太久了,我很困惑。 任何人都可以向我指出一种算法,它确定一个图形没有使用DFS的循环,或者我应该向我的教师狂奔?

I came around one of those questions in my exams:

Topologocial sorting using Kahn's Algorithm requires the graph to be DAG (Directed Acyclic Graph). How can we determine if a graph contains no cycles without using DFS/BFS first?

I am trying to answer that for too long now and I am baffled. Can anyone point out to me an algorithm that determines that a graph has no cycles that DOESN'T use DFS or should I go rampaging to my instructor?

最满意答案

当且仅当在kahn算法期间的某个时刻没有选择的源(并且剩余的图仍然不为空)时,存在一个循环

证明: Direction1 <-- :

如果存在循环,则将其设为v1->v2->v3->vk->v1 。 在算法的每一步, v1,v2,...,vk都不是源 - 通过显示你从不删除任何这些边来通过归纳证明它

Direction2 --> :

如果在kahn算法的某个时刻没有选择的源,虽然算法还没有完成,那么每个节点(在提醒图中)都有一个入局边缘。 假设没有循环,让v1->v2->..->vk成为提醒图中最长的简单路径。 但是, v1有一个入边,所以有一些节点v0使得v0->v1->...->vk也是一个路径,因为我们假设没有周期,所以它也是简单的路径。 与v1->..->vk最大性相矛盾

If and only if, at some point during kahn's algorithm has no source to choose (and the remaining graph is still none empty), there is a cycle

Proof: Direction1 <--:

If there is a cycle, let it be v1->v2->v3->vk->v1. At each step of the algorithm, none of v1,v2,...,vk is a source - proving it by induction by showing you never remove any of these edges

Direction2 -->:

If at some point during kahn's algorithm has no source to choose, though the algorithm is not finished yet, then every node (at the reminder graph) has an incoming edge. Assume there is no cycle, and let v1->v2->..->vk be the longest simple path in the reminder graph. But, v1 has an incoming edge, so there is some node v0 such that v0->v1->...->vk is also a path, and since we assumed there are no cycles, it is also simple path. Contradiction to maximality of v1->..->vk

更多推荐

本文发布于:2023-08-04 13:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415955.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   DFS   Determining   graph   cycle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!